package ca.canadapost.module.l2.fragments.idverification;

import android.app.Application;
import android.content.Context;
import androidx.lifecycle.a0;
import androidx.lifecycle.a1;
import androidx.lifecycle.d0;
import androidx.lifecycle.f0;
import androidx.lifecycle.g0;
import androidx.lifecycle.y0;
import ca.canadapost.core.data.auth.model.Name;
import ca.canadapost.core.data.auth.model.ProofingProfile;
import ca.canadapost.core.data.auth.model.ProofingProfileDTOKt;
import ca.canadapost.core.data.auth.model.ProofingResponse;
import ca.canadapost.core.data.auth.model.ProofingState;
import ca.canadapost.core.data.model.PhoneNumber;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import d9.f;
import dn.p;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import kotlin.jvm.internal.n;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import l8.h;
import rm.c0;
import rm.n0;
import rm.y;
import sm.q0;
import tp.m0;
import tp.o0;
import tp.u1;

/* loaded from: classes4.dex */
public final class a extends androidx.lifecycle.b implements l8.h, l8.c {
    private final jd.d A;
    private boolean B;
    private final d0 C;
    private final a0 D;
    private final a0 E;

    /* renamed from: c, reason: collision with root package name */
    private final t7.c f9870c;

    /* renamed from: d, reason: collision with root package name */
    private final g9.i f9871d;

    /* renamed from: e, reason: collision with root package name */
    private final d9.f f9872e;

    /* renamed from: f, reason: collision with root package name */
    private final g9.l f9873f;

    /* renamed from: g, reason: collision with root package name */
    private final ka.b f9874g;

    /* renamed from: h, reason: collision with root package name */
    private final fa.a f9875h;

    /* renamed from: i, reason: collision with root package name */
    private final /* synthetic */ l8.i f9876i;

    /* renamed from: j, reason: collision with root package name */
    private final /* synthetic */ l8.d f9877j;

    /* renamed from: k, reason: collision with root package name */
    private final l8.g f9878k;

    /* renamed from: l, reason: collision with root package name */
    private final a0 f9879l;

    /* renamed from: m, reason: collision with root package name */
    private final l8.g f9880m;

    /* renamed from: n, reason: collision with root package name */
    private final a0 f9881n;

    /* renamed from: o, reason: collision with root package name */
    private final l8.g f9882o;

    /* renamed from: p, reason: collision with root package name */
    private final a0 f9883p;

    /* renamed from: q, reason: collision with root package name */
    private final l8.g f9884q;

    /* renamed from: r, reason: collision with root package name */
    private final a0 f9885r;

    /* renamed from: s, reason: collision with root package name */
    private final l8.g f9886s;

    /* renamed from: t, reason: collision with root package name */
    private final a0 f9887t;

    /* renamed from: u, reason: collision with root package name */
    private final l8.g f9888u;

    /* renamed from: v, reason: collision with root package name */
    private final a0 f9889v;

    /* renamed from: w, reason: collision with root package name */
    private final l8.g f9890w;

    /* renamed from: x, reason: collision with root package name */
    private final a0 f9891x;

    /* renamed from: y, reason: collision with root package name */
    private final f0 f9892y;

    /* renamed from: z, reason: collision with root package name */
    private final a0 f9893z;

    /* renamed from: ca.canadapost.module.l2.fragments.idverification.a$a, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    static final class C0263a extends kotlin.coroutines.jvm.internal.l implements p {

        /* renamed from: p, reason: collision with root package name */
        int f9894p;

        C0263a(vm.d dVar) {
            super(2, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new C0263a(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f9894p;
            if (i10 == 0) {
                y.b(obj);
                g9.i iVar = a.this.f9871d;
                this.f9894p = 1;
                if (iVar.a(this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            a.this.c0();
            a.this.B = false;
            return n0.f34904a;
        }

        @Override // dn.p
        public final Object invoke(m0 m0Var, vm.d dVar) {
            return ((C0263a) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
        }
    }

    /* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */
    /* JADX WARN: Unknown enum class pattern. Please report as an issue! */
    /* loaded from: classes4.dex */
    public static final class b {
        private static final /* synthetic */ xm.a $ENTRIES;
        private static final /* synthetic */ b[] $VALUES;
        public static final b Success = new b("Success", 0);
        public static final b VerifyAtPostOffice = new b("VerifyAtPostOffice", 1);

        private static final /* synthetic */ b[] $values() {
            return new b[]{Success, VerifyAtPostOffice};
        }

        static {
            b[] $values = $values();
            $VALUES = $values;
            $ENTRIES = xm.b.a($values);
        }

        private b(String str, int i10) {
        }

        public static xm.a getEntries() {
            return $ENTRIES;
        }

        public static b valueOf(String str) {
            return (b) Enum.valueOf(b.class, str);
        }

        public static b[] values() {
            return (b[]) $VALUES.clone();
        }
    }

    /* loaded from: classes4.dex */
    static final class c extends v implements dn.l {

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ d0 f9897q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        c(d0 d0Var) {
            super(1);
            this.f9897q = d0Var;
        }

        public final void a(Name name) {
            if (a.this.B) {
                return;
            }
            this.f9897q.q(n0.f34904a);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((Name) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class d extends v implements dn.l {

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ d0 f9899q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        d(d0 d0Var) {
            super(1);
            this.f9899q = d0Var;
        }

        public final void a(ka.a aVar) {
            if (a.this.B) {
                return;
            }
            this.f9899q.q(n0.f34904a);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((ka.a) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class e extends v implements dn.l {

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ d0 f9901q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        e(d0 d0Var) {
            super(1);
            this.f9901q = d0Var;
        }

        public final void a(PhoneNumber phoneNumber) {
            if (a.this.B) {
                return;
            }
            this.f9901q.q(n0.f34904a);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((PhoneNumber) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class f extends v implements dn.l {

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ d0 f9903q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        f(d0 d0Var) {
            super(1);
            this.f9903q = d0Var;
        }

        public final void a(Date date) {
            if (a.this.B) {
                return;
            }
            this.f9903q.q(n0.f34904a);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((Date) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class g extends v implements dn.l {

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ d0 f9905q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        g(d0 d0Var) {
            super(1);
            this.f9905q = d0Var;
        }

        public final void a(ProofingState proofingState) {
            if (a.this.B) {
                return;
            }
            this.f9905q.q(n0.f34904a);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((ProofingState) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class h implements g0, n {

        /* renamed from: a, reason: collision with root package name */
        private final /* synthetic */ dn.l f9906a;

        h(dn.l function) {
            t.g(function, "function");
            this.f9906a = function;
        }

        @Override // kotlin.jvm.internal.n
        public final rm.i b() {
            return this.f9906a;
        }

        @Override // androidx.lifecycle.g0
        public final /* synthetic */ void d(Object obj) {
            this.f9906a.invoke(obj);
        }

        public final boolean equals(Object obj) {
            if ((obj instanceof g0) && (obj instanceof n)) {
                return t.b(b(), ((n) obj).b());
            }
            return false;
        }

        public final int hashCode() {
            return b().hashCode();
        }
    }

    /* loaded from: classes4.dex */
    static final class i extends v implements dn.a {
        i() {
            super(0);
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m156invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m156invoke() {
            a.this.r0("L2 - EditNameView");
            a.this.f9882o.s();
        }
    }

    /* loaded from: classes4.dex */
    static final class j extends v implements dn.a {
        j() {
            super(0);
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m157invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m157invoke() {
            a.this.f9884q.s();
        }
    }

    /* loaded from: classes4.dex */
    static final class k extends v implements dn.a {
        k() {
            super(0);
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m158invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m158invoke() {
            a.this.r0("L2 - PhoneNumberView");
            a.this.f9886s.s();
        }
    }

    /* loaded from: classes4.dex */
    static final class l extends v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        public static final l f9910p = new l();

        l() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final b invoke(ProofingState proofingState) {
            ProofingProfile latestProfile;
            if (proofingState == null || (latestProfile = proofingState.getLatestProfile()) == null) {
                return null;
            }
            String proofingProfileStatus = latestProfile.getProofingProfileStatus();
            if (t.b(proofingProfileStatus, ProofingProfileDTOKt.PROOFING_PROFILE_ACTIVE)) {
                return b.Success;
            }
            if (t.b(proofingProfileStatus, ProofingProfileDTOKt.PROOFING_PROFILE_INCOMPLETE) && proofingState.isAccountLocked()) {
                return b.VerifyAtPostOffice;
            }
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class m extends kotlin.coroutines.jvm.internal.l implements p {

        /* renamed from: p, reason: collision with root package name */
        int f9911p;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ Name f9913r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ ka.a f9914s;

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ PhoneNumber f9915t;

        /* renamed from: u, reason: collision with root package name */
        final /* synthetic */ Date f9916u;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        m(Name name, ka.a aVar, PhoneNumber phoneNumber, Date date, vm.d dVar) {
            super(2, dVar);
            this.f9913r = name;
            this.f9914s = aVar;
            this.f9915t = phoneNumber;
            this.f9916u = date;
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new m(this.f9913r, this.f9914s, this.f9915t, this.f9916u, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            Map p10;
            f10 = wm.d.f();
            int i10 = this.f9911p;
            if (i10 == 0) {
                y.b(obj);
                f.a.a(a.this.f9872e, "L2 - Proofing Attempted_Adobe", null, 2, null);
                g9.i iVar = a.this.f9871d;
                Name name = this.f9913r;
                ka.a aVar = this.f9914s;
                PhoneNumber phoneNumber = this.f9915t;
                Date date = this.f9916u;
                this.f9911p = 1;
                obj = iVar.h(name, aVar, phoneNumber, date, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    if (i10 == 2) {
                        y.b(obj);
                        a.this.f9878k.s();
                        return n0.f34904a;
                    }
                    if (i10 != 3) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    y.b(obj);
                    a.this.f9878k.s();
                    return n0.f34904a;
                }
                y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Success) {
                ProofingResponse proofingResponse = (ProofingResponse) ((ResultWrapper.Success) resultWrapper).getData();
                String proofingProfileStatus = proofingResponse.getProofingProfileStatus();
                Locale locale = Locale.ROOT;
                String upperCase = proofingProfileStatus.toUpperCase(locale);
                t.f(upperCase, "toUpperCase(...)");
                if (!t.b(upperCase, "INCOMPLETE") || ((!t.b(proofingResponse.isAccountLocked(), kotlin.coroutines.jvm.internal.b.a(true)) || a.this.B) && a.this.f9871d.e() <= 3)) {
                    String upperCase2 = proofingResponse.getProofingProfileStatus().toUpperCase(locale);
                    t.f(upperCase2, "toUpperCase(...)");
                    if (t.b(upperCase2, "ABANDONED")) {
                        ka.b bVar = a.this.f9874g;
                        this.f9911p = 2;
                        if (bVar.D(this) == f10) {
                            return f10;
                        }
                        a.this.f9878k.s();
                    } else {
                        String upperCase3 = proofingResponse.getProofingProfileStatus().toUpperCase(locale);
                        t.f(upperCase3, "toUpperCase(...)");
                        if (!t.b(upperCase3, "INCOMPLETE") || a.this.f9871d.e() > 3) {
                            ka.b bVar2 = a.this.f9874g;
                            this.f9911p = 3;
                            if (bVar2.D(this) == f10) {
                                return f10;
                            }
                            a.this.f9878k.s();
                        } else {
                            d9.f fVar = a.this.f9872e;
                            p10 = q0.p(d9.e.f15943f.a("User-IdentityVerification_L2"), c0.a("e.Var13", a.this.f9871d.o()));
                            fVar.b("common_L2Failure_verify_Adobe", p10);
                            a.this.f9890w.s();
                        }
                    }
                } else {
                    a.this.f9880m.s();
                }
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                f.a.a(a.this.f9872e, "L2 - Proofing System Error_Adobe", null, 2, null);
                a.this.o0((ResultWrapper.Error) resultWrapper, true);
            }
            return n0.f34904a;
        }

        @Override // dn.p
        public final Object invoke(m0 m0Var, vm.d dVar) {
            return ((m) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
        }
    }

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public a(t7.c contextService, g9.i l2Repository, d9.f analyticsService, g9.l userAuthenticationRepository, ka.b userProfileRepository, fa.a myMailRepository, ka.b profileRepository) {
        super((Application) r0);
        t.g(contextService, "contextService");
        t.g(l2Repository, "l2Repository");
        t.g(analyticsService, "analyticsService");
        t.g(userAuthenticationRepository, "userAuthenticationRepository");
        t.g(userProfileRepository, "userProfileRepository");
        t.g(myMailRepository, "myMailRepository");
        t.g(profileRepository, "profileRepository");
        Context a10 = contextService.a();
        t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f9870c = contextService;
        this.f9871d = l2Repository;
        this.f9872e = analyticsService;
        this.f9873f = userAuthenticationRepository;
        this.f9874g = userProfileRepository;
        this.f9875h = myMailRepository;
        this.f9876i = new l8.i(contextService);
        this.f9877j = new l8.d();
        l8.g gVar = new l8.g();
        this.f9878k = gVar;
        this.f9879l = gVar;
        l8.g gVar2 = new l8.g();
        this.f9880m = gVar2;
        this.f9881n = gVar2;
        l8.g gVar3 = new l8.g();
        this.f9882o = gVar3;
        this.f9883p = gVar3;
        l8.g gVar4 = new l8.g();
        this.f9884q = gVar4;
        this.f9885r = gVar4;
        l8.g gVar5 = new l8.g();
        this.f9886s = gVar5;
        this.f9887t = gVar5;
        l8.g gVar6 = new l8.g();
        this.f9888u = gVar6;
        this.f9889v = gVar6;
        l8.g gVar7 = new l8.g();
        this.f9890w = gVar7;
        this.f9891x = gVar7;
        f0 f0Var = new f0();
        this.f9892y = f0Var;
        this.f9893z = f0Var;
        this.A = new jd.d(P(), l2Repository, t.b(profileRepository.G().f(), Boolean.TRUE), myMailRepository, new i(), new j(), new k());
        this.B = true;
        d0 d0Var = new d0();
        d0Var.r(l2Repository.d(), new h(new c(d0Var)));
        d0Var.r(l2Repository.i(), new h(new d(d0Var)));
        d0Var.r(l2Repository.b(), new h(new e(d0Var)));
        d0Var.r(l2Repository.f(), new h(new f(d0Var)));
        d0Var.r(l2Repository.c(), new h(new g(d0Var)));
        this.C = d0Var;
        this.D = d0Var;
        this.E = y0.a(l2Repository.c(), l.f9910p);
        r0("User-IdentityVerification_L2");
        h.a.a(this, a1.a(this), null, null, null, new C0263a(null), 7, null);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void r0(String str) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("e.Var13", this.f9871d.o());
        this.f9872e.c(str, linkedHashMap);
    }

    private final void s0() {
        ka.a aVar = (ka.a) this.f9871d.i().f();
        Name name = (Name) this.f9871d.d().f();
        PhoneNumber phoneNumber = (PhoneNumber) this.f9871d.b().f();
        Date date = (Date) this.f9871d.f().f();
        if (phoneNumber == null && date == null) {
            this.f9892y.q(this.A.a(true));
        } else if (aVar == null || name == null) {
            o0(new ResultWrapper.Error(null, null, RepositoryError.Unknown, null, 8, null), true);
        } else {
            h.a.a(this, a1.a(this), null, null, this.f9870c.getString(ed.m.f16954k), new m(name, aVar, phoneNumber, date, null), 3, null);
        }
    }

    @Override // l8.h
    public a0 J() {
        return this.f9876i.J();
    }

    public final void c0() {
        this.f9892y.q(jd.d.b(this.A, false, 1, null));
    }

    public final a0 d0() {
        return this.D;
    }

    public final a0 e0() {
        return this.f9893z;
    }

    public final fa.a f0() {
        return this.f9875h;
    }

    public final a0 g0() {
        return this.f9879l;
    }

    public final a0 h0() {
        return this.f9881n;
    }

    public final a0 i0() {
        return this.f9885r;
    }

    public final a0 j0() {
        return this.f9883p;
    }

    public final a0 k0() {
        return this.f9887t;
    }

    public final a0 l0() {
        return this.f9889v;
    }

    public final a0 m0() {
        return this.f9891x;
    }

    public final a0 n0() {
        return this.E;
    }

    @Override // l8.c
    public a0 o() {
        return this.f9877j.o();
    }

    public void o0(ResultWrapper.Error error, boolean z10) {
        t.g(error, "error");
        this.f9877j.a(error, z10);
    }

    public final void p0() {
        r0("L2 - HowToVerifyView");
        this.f9888u.s();
    }

    public final void q0() {
        Map p10;
        if (this.f9873f.b() == d9.b.MY_MAIL_FLOW) {
            d9.f fVar = this.f9872e;
            p10 = q0.p(d9.e.f15943f.a("User-IdentityVerification_L2"), c0.a("e.Var13", this.f9871d.o()));
            fVar.b("User-IdentityVerification_L2_Click_Verify_Adobe", p10);
        }
        s0();
    }

    @Override // l8.c
    public a0 t() {
        return this.f9877j.t();
    }

    @Override // l8.h
    public u1 u(m0 m0Var, vm.g context, o0 start, String str, p block) {
        t.g(m0Var, "<this>");
        t.g(context, "context");
        t.g(start, "start");
        t.g(block, "block");
        return this.f9876i.u(m0Var, context, start, str, block);
    }
}
