package com.revenuecat.purchases.models;

import com.revenuecat.purchases.InternalRevenueCatAPI;
import com.revenuecat.purchases.common.verification.SigningManager;
import g5.a;
import j5.b;
import java.lang.annotation.Annotation;
import java.security.MessageDigest;
import java.util.Locale;
import k5.P;
import k5.a0;
import kotlin.jvm.internal.o;
import kotlin.jvm.internal.p;
import m1.g;
import w4.InterfaceC3141c;
import w4.h;
import w4.i;

/* JADX INFO: loaded from: classes3.dex */
@InternalRevenueCatAPI
public final class Checksum {
    private final Algorithm algorithm;
    private final String value;
    public static final Companion Companion = new Companion(null);
    private static final a[] $childSerializers = {Algorithm.Companion.serializer(), null};

    public enum Algorithm {
        SHA256("SHA-256"),
        SHA384("SHA-384"),
        SHA512("SHA-512"),
        MD5("MD5");

        private final String algorithmName;
        public static final Companion Companion = new Companion(null);
        private static final h $cachedSerializer$delegate = g.j(i.f25466b, Companion.AnonymousClass1.INSTANCE);

        public static final class Companion {

            /* JADX INFO: renamed from: com.revenuecat.purchases.models.Checksum$Algorithm$Companion$1, reason: invalid class name */
            public static final class AnonymousClass1 extends p implements J4.a {
                public static final AnonymousClass1 INSTANCE = new AnonymousClass1();

                public AnonymousClass1() {
                    super(0);
                }

                @Override // J4.a
                public final a invoke() {
                    return P.d("com.revenuecat.purchases.models.Checksum.Algorithm", Algorithm.values(), new String[]{SigningManager.POST_PARAMS_ALGORITHM, "sha384", "sha512", "md5"}, new Annotation[][]{null, null, null, null});
                }
            }

            public /* synthetic */ Companion(kotlin.jvm.internal.h hVar) {
                this();
            }

            private final /* synthetic */ a get$cachedSerializer() {
                return (a) Algorithm.$cachedSerializer$delegate.getValue();
            }

            /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
            public final Algorithm fromString(String value) {
                o.h(value, "value");
                String lowerCase = value.toLowerCase(Locale.ROOT);
                o.g(lowerCase, "toLowerCase(...)");
                switch (lowerCase.hashCode()) {
                    case -903629273:
                        if (lowerCase.equals(SigningManager.POST_PARAMS_ALGORITHM)) {
                            return Algorithm.SHA256;
                        }
                        return null;
                    case -903628221:
                        if (lowerCase.equals("sha384")) {
                            return Algorithm.SHA384;
                        }
                        return null;
                    case -903626518:
                        if (lowerCase.equals("sha512")) {
                            return Algorithm.SHA512;
                        }
                        return null;
                    case 107902:
                        if (lowerCase.equals("md5")) {
                            return Algorithm.MD5;
                        }
                        return null;
                    default:
                        return null;
                }
            }

            public final a serializer() {
                return get$cachedSerializer();
            }

            private Companion() {
            }
        }

        Algorithm(String str) {
            this.algorithmName = str;
        }

        public final String getAlgorithmName() {
            return this.algorithmName;
        }
    }

    public static final class ChecksumValidationException extends Exception {
    }

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

        public final Checksum generate(byte[] data, Algorithm algorithm) {
            o.h(data, "data");
            o.h(algorithm, "algorithm");
            byte[] hash = MessageDigest.getInstance(algorithm.getAlgorithmName()).digest(data);
            o.g(hash, "hash");
            return new Checksum(algorithm, ChecksumKt.toHexString(hash));
        }

        public final a serializer() {
            return Checksum$$serializer.INSTANCE;
        }

        private Companion() {
        }
    }

    @InterfaceC3141c
    public /* synthetic */ Checksum(int i6, Algorithm algorithm, String str, a0 a0Var) {
        if (3 != (i6 & 3)) {
            P.h(i6, 3, Checksum$$serializer.INSTANCE.getDescriptor());
            throw null;
        }
        this.algorithm = algorithm;
        this.value = str;
    }

    public static /* synthetic */ Checksum copy$default(Checksum checksum, Algorithm algorithm, String str, int i6, Object obj) {
        if ((i6 & 1) != 0) {
            algorithm = checksum.algorithm;
        }
        if ((i6 & 2) != 0) {
            str = checksum.value;
        }
        return checksum.copy(algorithm, str);
    }

    public static /* synthetic */ void getAlgorithm$annotations() {
    }

    public static /* synthetic */ void getValue$annotations() {
    }

    public static final /* synthetic */ void write$Self$purchases_defaultsBc8Release(Checksum checksum, b bVar, i5.g gVar) {
        bVar.z(gVar, 0, $childSerializers[0], checksum.algorithm);
        bVar.A(gVar, 1, checksum.value);
    }

    public final Algorithm component1() {
        return this.algorithm;
    }

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

    public final Checksum copy(Algorithm algorithm, String value) {
        o.h(algorithm, "algorithm");
        o.h(value, "value");
        return new Checksum(algorithm, value);
    }

    public boolean equals(Object obj) {
        if (!(obj instanceof Checksum)) {
            return false;
        }
        String str = this.value;
        Locale locale = Locale.ROOT;
        String lowerCase = str.toLowerCase(locale);
        o.g(lowerCase, "toLowerCase(...)");
        Checksum checksum = (Checksum) obj;
        String lowerCase2 = checksum.value.toLowerCase(locale);
        o.g(lowerCase2, "toLowerCase(...)");
        return lowerCase.equals(lowerCase2) && this.algorithm == checksum.algorithm;
    }

    public final Algorithm getAlgorithm() {
        return this.algorithm;
    }

    public final String getValue() {
        return this.value;
    }

    public int hashCode() {
        return this.value.hashCode() + (this.algorithm.hashCode() * 31);
    }

    public String toString() {
        StringBuilder sb = new StringBuilder("Checksum(algorithm=");
        sb.append(this.algorithm);
        sb.append(", value=");
        return Z0.o.r(sb, this.value, ')');
    }

    public Checksum(Algorithm algorithm, String value) {
        o.h(algorithm, "algorithm");
        o.h(value, "value");
        this.algorithm = algorithm;
        this.value = value;
    }
}
