package com.revenuecat.purchases.common.networking;

import S4.p;
import com.google.android.recaptcha.internal.a;
import com.revenuecat.purchases.InternalRevenueCatAPI;
import com.revenuecat.purchases.VerificationResult;
import com.revenuecat.purchases.common.BackendHelperKt;
import com.revenuecat.purchases.common.LogWrapperKt;
import java.util.Date;
import kotlin.jvm.internal.h;
import kotlin.jvm.internal.o;
import org.json.JSONException;
import org.json.JSONObject;
import q.AbstractC2761L;

/* JADX INFO: loaded from: classes3.dex */
@InternalRevenueCatAPI
public final class HTTPResult {
    public static final Companion Companion = new Companion(null);
    public static final String ETAG_HEADER_NAME = "X-RevenueCat-ETag";
    public static final String LOAD_SHEDDER_HEADER_NAME = "x-revenuecat-fortress";
    public static final String REQUEST_TIME_HEADER_NAME = "X-RevenueCat-Request-Time";
    public static final String SIGNATURE_HEADER_NAME = "X-Signature";
    private final Integer backendErrorCode;
    private final String backendErrorMessage;
    private final JSONObject body;
    private final boolean isFallbackURL;
    private final boolean isLoadShedderResponse;
    private final Origin origin;
    private final String payload;
    private final Date requestDate;
    private final int responseCode;
    private final VerificationResult verificationResult;

    public static final class Companion {
        public /* synthetic */ Companion(h hVar) {
            this();
        }

        public final HTTPResult deserialize$purchases_defaultsBc8Release(String serialized) throws JSONException {
            Origin originValueOf;
            VerificationResult verificationResultValueOf;
            o.h(serialized, "serialized");
            JSONObject jSONObject = new JSONObject(serialized);
            int i6 = jSONObject.getInt("responseCode");
            String payload = jSONObject.getString("payload");
            if (jSONObject.has("origin")) {
                String string = jSONObject.getString("origin");
                o.g(string, "jsonObject.getString(SERIALIZATION_NAME_ORIGIN)");
                originValueOf = Origin.valueOf(string);
            } else {
                originValueOf = Origin.CACHE;
            }
            Origin origin = originValueOf;
            Date date = jSONObject.has("requestDate") ? new Date(jSONObject.getLong("requestDate")) : null;
            if (jSONObject.has("verificationResult")) {
                String string2 = jSONObject.getString("verificationResult");
                o.g(string2, "jsonObject.getString(SER…NAME_VERIFICATION_RESULT)");
                verificationResultValueOf = VerificationResult.valueOf(string2);
            } else {
                verificationResultValueOf = VerificationResult.NOT_REQUESTED;
            }
            VerificationResult verificationResult = verificationResultValueOf;
            boolean z6 = jSONObject.has("isLoadShedderResponse") ? jSONObject.getBoolean("isLoadShedderResponse") : false;
            boolean z7 = jSONObject.has("isFallbackURL") ? jSONObject.getBoolean("isFallbackURL") : false;
            o.g(payload, "payload");
            return new HTTPResult(i6, payload, origin, date, verificationResult, z6, z7);
        }

        private Companion() {
        }
    }

    public enum Origin {
        BACKEND,
        CACHE
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0045  */
    /* JADX WARN: Removed duplicated region for block: B:19:0x0063  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public HTTPResult(int i6, String payload, Origin origin, Date date, VerificationResult verificationResult, boolean z6, boolean z7) {
        JSONObject jSONObject;
        Integer numValueOf;
        o.h(payload, "payload");
        o.h(origin, "origin");
        o.h(verificationResult, "verificationResult");
        this.responseCode = i6;
        this.payload = payload;
        this.origin = origin;
        this.requestDate = date;
        this.verificationResult = verificationResult;
        this.isLoadShedderResponse = z6;
        this.isFallbackURL = z7;
        String str = null;
        payload = p.Q0(payload) ? null : payload;
        if (payload != null) {
            try {
                jSONObject = new JSONObject(payload);
            } catch (JSONException e6) {
                LogWrapperKt.getCurrentLogHandler().e("[Purchases] - ERROR", "Failed to parse payload as JSON: ".concat(payload), e6);
                jSONObject = null;
            }
            jSONObject = jSONObject == null ? new JSONObject() : jSONObject;
        }
        this.body = jSONObject;
        if (!BackendHelperKt.isSuccessful(this)) {
            numValueOf = Integer.valueOf(jSONObject.optInt("code"));
            numValueOf = numValueOf.intValue() <= 0 ? null : numValueOf;
        }
        this.backendErrorCode = numValueOf;
        if (!BackendHelperKt.isSuccessful(this)) {
            String it = jSONObject.optString("message");
            o.g(it, "it");
            if (!p.Q0(it)) {
                str = it;
            }
        }
        this.backendErrorMessage = str;
    }

    public static /* synthetic */ HTTPResult copy$default(HTTPResult hTTPResult, int i6, String str, Origin origin, Date date, VerificationResult verificationResult, boolean z6, boolean z7, int i7, Object obj) {
        if ((i7 & 1) != 0) {
            i6 = hTTPResult.responseCode;
        }
        if ((i7 & 2) != 0) {
            str = hTTPResult.payload;
        }
        if ((i7 & 4) != 0) {
            origin = hTTPResult.origin;
        }
        if ((i7 & 8) != 0) {
            date = hTTPResult.requestDate;
        }
        if ((i7 & 16) != 0) {
            verificationResult = hTTPResult.verificationResult;
        }
        if ((i7 & 32) != 0) {
            z6 = hTTPResult.isLoadShedderResponse;
        }
        if ((i7 & 64) != 0) {
            z7 = hTTPResult.isFallbackURL;
        }
        boolean z8 = z6;
        boolean z9 = z7;
        VerificationResult verificationResult2 = verificationResult;
        Origin origin2 = origin;
        return hTTPResult.copy(i6, str, origin2, date, verificationResult2, z8, z9);
    }

    public final int component1() {
        return this.responseCode;
    }

    public final String component2() {
        return this.payload;
    }

    public final Origin component3() {
        return this.origin;
    }

    public final Date component4() {
        return this.requestDate;
    }

    public final VerificationResult component5() {
        return this.verificationResult;
    }

    public final boolean component6() {
        return this.isLoadShedderResponse;
    }

    public final boolean component7() {
        return this.isFallbackURL;
    }

    public final HTTPResult copy(int i6, String payload, Origin origin, Date date, VerificationResult verificationResult, boolean z6, boolean z7) {
        o.h(payload, "payload");
        o.h(origin, "origin");
        o.h(verificationResult, "verificationResult");
        return new HTTPResult(i6, payload, origin, date, verificationResult, z6, z7);
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof HTTPResult)) {
            return false;
        }
        HTTPResult hTTPResult = (HTTPResult) obj;
        return this.responseCode == hTTPResult.responseCode && o.c(this.payload, hTTPResult.payload) && this.origin == hTTPResult.origin && o.c(this.requestDate, hTTPResult.requestDate) && this.verificationResult == hTTPResult.verificationResult && this.isLoadShedderResponse == hTTPResult.isLoadShedderResponse && this.isFallbackURL == hTTPResult.isFallbackURL;
    }

    public final Integer getBackendErrorCode() {
        return this.backendErrorCode;
    }

    public final String getBackendErrorMessage() {
        return this.backendErrorMessage;
    }

    public final JSONObject getBody() {
        return this.body;
    }

    public final Origin getOrigin() {
        return this.origin;
    }

    public final String getPayload() {
        return this.payload;
    }

    public final Date getRequestDate() {
        return this.requestDate;
    }

    public final int getResponseCode() {
        return this.responseCode;
    }

    public final VerificationResult getVerificationResult() {
        return this.verificationResult;
    }

    public int hashCode() {
        int iHashCode = (this.origin.hashCode() + AbstractC2761L.b(Integer.hashCode(this.responseCode) * 31, 31, this.payload)) * 31;
        Date date = this.requestDate;
        return Boolean.hashCode(this.isFallbackURL) + a.f((this.verificationResult.hashCode() + ((iHashCode + (date == null ? 0 : date.hashCode())) * 31)) * 31, 31, this.isLoadShedderResponse);
    }

    public final boolean isFallbackURL() {
        return this.isFallbackURL;
    }

    public final boolean isLoadShedderResponse() {
        return this.isLoadShedderResponse;
    }

    public final String serialize$purchases_defaultsBc8Release() throws JSONException {
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("responseCode", this.responseCode);
        jSONObject.put("payload", this.payload);
        jSONObject.put("origin", this.origin.name());
        Date date = this.requestDate;
        jSONObject.put("requestDate", date != null ? Long.valueOf(date.getTime()) : null);
        jSONObject.put("verificationResult", this.verificationResult.name());
        jSONObject.put("isLoadShedderResponse", this.isLoadShedderResponse);
        jSONObject.put("isFallbackURL", this.isFallbackURL);
        String string = jSONObject.toString();
        o.g(string, "jsonObject.toString()");
        return string;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder("HTTPResult(responseCode=");
        sb.append(this.responseCode);
        sb.append(", payload=");
        sb.append(this.payload);
        sb.append(", origin=");
        sb.append(this.origin);
        sb.append(", requestDate=");
        sb.append(this.requestDate);
        sb.append(", verificationResult=");
        sb.append(this.verificationResult);
        sb.append(", isLoadShedderResponse=");
        sb.append(this.isLoadShedderResponse);
        sb.append(", isFallbackURL=");
        return AbstractC2761L.h(sb, this.isFallbackURL, ')');
    }
}
