package ca.canadapost.core.data.model;

import java.util.regex.Pattern;
import kotlin.Metadata;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import kotlin.text.l;
import kotlin.text.y;

@Metadata(d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\r\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0004\b\u0086\b\u0018\u0000 \u001b2\u00020\u0001:\u0001\u001bB%\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0003\u0012\u0006\u0010\u0005\u001a\u00020\u0003\u0012\u0006\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bJ\t\u0010\u000f\u001a\u00020\u0003HÆ\u0003J\t\u0010\u0010\u001a\u00020\u0003HÆ\u0003J\t\u0010\u0011\u001a\u00020\u0003HÆ\u0003J\t\u0010\u0012\u001a\u00020\u0007HÆ\u0003J1\u0010\u0013\u001a\u00020\u00002\b\b\u0002\u0010\u0002\u001a\u00020\u00032\b\b\u0002\u0010\u0004\u001a\u00020\u00032\b\b\u0002\u0010\u0005\u001a\u00020\u00032\b\b\u0002\u0010\u0006\u001a\u00020\u0007HÆ\u0001J\u0013\u0010\u0014\u001a\u00020\u00152\b\u0010\u0016\u001a\u0004\u0018\u00010\u0001HÖ\u0003J\t\u0010\u0017\u001a\u00020\u0018HÖ\u0001J\u0006\u0010\u0019\u001a\u00020\u0003J\b\u0010\u001a\u001a\u00020\u0003H\u0016R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\t\u0010\nR\u0011\u0010\u0004\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\nR\u0011\u0010\u0005\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\f\u0010\nR\u0011\u0010\u0006\u001a\u00020\u0007¢\u0006\b\n\u0000\u001a\u0004\b\r\u0010\u000e¨\u0006\u001c"}, d2 = {"Lca/canadapost/core/data/model/PhoneNumber;", "", "areaCode", "", "prefix", "suffix", "type", "Lca/canadapost/core/data/model/PhoneNumberFormat;", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lca/canadapost/core/data/model/PhoneNumberFormat;)V", "getAreaCode", "()Ljava/lang/String;", "getPrefix", "getSuffix", "getType", "()Lca/canadapost/core/data/model/PhoneNumberFormat;", "component1", "component2", "component3", "component4", "copy", "equals", "", "other", "hashCode", "", "masked", "toString", "Companion", "core_data_productionRelease"}, k = 1, mv = {1, 9, 0}, xi = 48)
/* loaded from: classes.dex */
public final /* data */ class PhoneNumber {

    /* renamed from: Companion, reason: from kotlin metadata */
    public static final Companion INSTANCE = new Companion(null);
    private static final String PHONE_VALIDATION_PATTERN = "^[(]{0,1}(\\d{3})[)-]{0,1}(\\d{3})[-]{0,1}(\\d{4})$";
    private final String areaCode;
    private final String prefix;
    private final String suffix;
    private final PhoneNumberFormat type;

    @Metadata(d1 = {"\u0000(\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0005\u001a\u00020\u00062\b\u0010\u0007\u001a\u0004\u0018\u00010\u0004J\u000e\u0010\b\u001a\u00020\u00042\u0006\u0010\t\u001a\u00020\u0004J\u001c\u0010\n\u001a\u0004\u0018\u00010\u000b2\b\u0010\t\u001a\u0004\u0018\u00010\u00042\b\b\u0002\u0010\f\u001a\u00020\rJ\u000e\u0010\u000e\u001a\u00020\u00042\u0006\u0010\t\u001a\u00020\u0004R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000¨\u0006\u000f"}, d2 = {"Lca/canadapost/core/data/model/PhoneNumber$Companion;", "", "()V", "PHONE_VALIDATION_PATTERN", "", "isValidPhoneNumber", "", "phone", "normalizePhoneNumber", "phoneNumber", "parsePhoneNumber", "Lca/canadapost/core/data/model/PhoneNumber;", "type", "Lca/canadapost/core/data/model/PhoneNumberFormat;", "removeSpecChars", "core_data_productionRelease"}, k = 1, mv = {1, 9, 0}, xi = 48)
    /* loaded from: classes.dex */
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(k kVar) {
            this();
        }

        public static /* synthetic */ PhoneNumber parsePhoneNumber$default(Companion companion, String str, PhoneNumberFormat phoneNumberFormat, int i10, Object obj) {
            if ((i10 & 2) != 0) {
                phoneNumberFormat = PhoneNumberFormat.FORMAT1;
            }
            return companion.parsePhoneNumber(str, phoneNumberFormat);
        }

        /* JADX WARN: Removed duplicated region for block: B:7:0x000f A[RETURN] */
        /* JADX WARN: Removed duplicated region for block: B:9:0x0010  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final boolean isValidPhoneNumber(String phone) {
            boolean z10;
            String J;
            boolean C;
            if (phone != null) {
                C = y.C(phone);
                if (!C) {
                    z10 = false;
                    if (!z10) {
                        return false;
                    }
                    J = y.J(phone, " ", "", false, 4, null);
                    return Pattern.compile(PhoneNumber.PHONE_VALIDATION_PATTERN).matcher(J).matches();
                }
            }
            z10 = true;
            if (!z10) {
            }
        }

        public final String normalizePhoneNumber(String phoneNumber) {
            t.g(phoneNumber, "phoneNumber");
            return new l("[^\\d.]").g(phoneNumber, "");
        }

        public final PhoneNumber parsePhoneNumber(String phoneNumber, PhoneNumberFormat type) {
            t.g(type, "type");
            if (phoneNumber != null && isValidPhoneNumber(phoneNumber)) {
                try {
                    String normalizePhoneNumber = normalizePhoneNumber(phoneNumber);
                    String substring = normalizePhoneNumber.substring(0, 3);
                    t.f(substring, "substring(...)");
                    String substring2 = normalizePhoneNumber.substring(3, 6);
                    t.f(substring2, "substring(...)");
                    String substring3 = normalizePhoneNumber.substring(6, 10);
                    t.f(substring3, "substring(...)");
                    return new PhoneNumber(substring, substring2, substring3, type);
                } catch (Throwable unused) {
                }
            }
            return null;
        }

        public final String removeSpecChars(String phoneNumber) {
            t.g(phoneNumber, "phoneNumber");
            return new l("[^A-Za-z0-9]").g(phoneNumber, "");
        }
    }

    public PhoneNumber(String areaCode, String prefix, String suffix, PhoneNumberFormat type) {
        t.g(areaCode, "areaCode");
        t.g(prefix, "prefix");
        t.g(suffix, "suffix");
        t.g(type, "type");
        this.areaCode = areaCode;
        this.prefix = prefix;
        this.suffix = suffix;
        this.type = type;
    }

    public static /* synthetic */ PhoneNumber copy$default(PhoneNumber phoneNumber, String str, String str2, String str3, PhoneNumberFormat phoneNumberFormat, int i10, Object obj) {
        if ((i10 & 1) != 0) {
            str = phoneNumber.areaCode;
        }
        if ((i10 & 2) != 0) {
            str2 = phoneNumber.prefix;
        }
        if ((i10 & 4) != 0) {
            str3 = phoneNumber.suffix;
        }
        if ((i10 & 8) != 0) {
            phoneNumberFormat = phoneNumber.type;
        }
        return phoneNumber.copy(str, str2, str3, phoneNumberFormat);
    }

    /* renamed from: component1, reason: from getter */
    public final String getAreaCode() {
        return this.areaCode;
    }

    /* renamed from: component2, reason: from getter */
    public final String getPrefix() {
        return this.prefix;
    }

    /* renamed from: component3, reason: from getter */
    public final String getSuffix() {
        return this.suffix;
    }

    /* renamed from: component4, reason: from getter */
    public final PhoneNumberFormat getType() {
        return this.type;
    }

    public final PhoneNumber copy(String areaCode, String prefix, String suffix, PhoneNumberFormat type) {
        t.g(areaCode, "areaCode");
        t.g(prefix, "prefix");
        t.g(suffix, "suffix");
        t.g(type, "type");
        return new PhoneNumber(areaCode, prefix, suffix, type);
    }

    public boolean equals(Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof PhoneNumber)) {
            return false;
        }
        PhoneNumber phoneNumber = (PhoneNumber) other;
        return t.b(this.areaCode, phoneNumber.areaCode) && t.b(this.prefix, phoneNumber.prefix) && t.b(this.suffix, phoneNumber.suffix) && this.type == phoneNumber.type;
    }

    public final String getAreaCode() {
        return this.areaCode;
    }

    public final String getPrefix() {
        return this.prefix;
    }

    public final String getSuffix() {
        return this.suffix;
    }

    public final PhoneNumberFormat getType() {
        return this.type;
    }

    public int hashCode() {
        return (((((this.areaCode.hashCode() * 31) + this.prefix.hashCode()) * 31) + this.suffix.hashCode()) * 31) + this.type.hashCode();
    }

    public final String masked() {
        return "******" + this.suffix;
    }

    public String toString() {
        if (this.type != PhoneNumberFormat.FORMAT1) {
            return this.areaCode + "-" + this.prefix + "-" + this.suffix;
        }
        return "(" + this.areaCode + ") " + this.prefix + "-" + this.suffix;
    }
}
