package ca.canadapost.module.l1auth.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.ProofingResponse;
import ca.canadapost.core.data.auth.model.ProofingState;
import ca.canadapost.core.data.auth.model.VerifyDobFlow;
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.List;
import java.util.Map;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import l8.h;
import rm.c0;
import rm.n0;
import rm.y;
import sm.p0;
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 a0 A;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* renamed from: s, reason: collision with root package name */
    private final dd.d f9737s;

    /* renamed from: t, reason: collision with root package name */
    private boolean f9738t;

    /* renamed from: u, reason: collision with root package name */
    private final d0 f9739u;

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

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

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

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

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

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

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

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

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

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

        @Override // dn.p
        public final Object invoke(m0 m0Var, vm.d dVar) {
            return ((C0261a) 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 f9748q;

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

        public final void a(Name name) {
            if (a.this.f9738t) {
                return;
            }
            this.f9748q.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 f9750q;

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

        public final void a(ka.a aVar) {
            if (a.this.f9738t) {
                return;
            }
            this.f9750q.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 f9752q;

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

        public final void a(PhoneNumber phoneNumber) {
            if (a.this.f9738t) {
                return;
            }
            this.f9752q.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 f9754q;

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

        public final void a(Date date) {
            if (a.this.f9738t) {
                return;
            }
            this.f9754q.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 f9756q;

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

        public final void a(ProofingState proofingState) {
            if (a.this.f9738t) {
                return;
            }
            this.f9756q.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, kotlin.jvm.internal.n {

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

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

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

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

        public final boolean equals(Object obj) {
            if ((obj instanceof g0) && (obj instanceof kotlin.jvm.internal.n)) {
                return t.b(b(), ((kotlin.jvm.internal.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() {
            m151invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m151invoke() {
            a.this.f9727i.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() {
            m152invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m152invoke() {
            a.this.f9729k.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() {
            m153invoke();
            return n0.f34904a;
        }

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

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

        public final void a(VerifyDobFlow it) {
            Map e10;
            t.g(it, "it");
            d9.f fVar = a.this.f9723e;
            e10 = p0.e(c0.a("e.Var3", "User-IdentityVerification"));
            fVar.b("Add_date_of_birth_link_click_Adobe", e10);
            a.this.f9733o.q(it);
        }

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

    /* loaded from: classes4.dex */
    static final class m extends v implements dn.l {
        m() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final b invoke(ProofingState proofingState) {
            b bVar;
            if (proofingState == null) {
                return null;
            }
            a aVar = a.this;
            if (proofingState.getActiveProofingProfile() != null) {
                bVar = b.Success;
            } else {
                if (proofingState.getIncompleteProofingProfile() == null) {
                    return null;
                }
                if (!proofingState.isAccountLocked() && aVar.f9738t) {
                    return null;
                }
                bVar = b.VerifyAtPostOffice;
            }
            return bVar;
        }
    }

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

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

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new n(this.f9765r, this.f9766s, this.f9767t, this.f9768u, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            List<ProofingProfile> proofingProfiles;
            f10 = wm.d.f();
            int i10 = this.f9763p;
            if (i10 == 0) {
                y.b(obj);
                f.a.a(a.this.f9723e, "L1 - Proofing Attempted_Adobe", null, 2, null);
                g9.h hVar = a.this.f9722d;
                Name name = this.f9765r;
                ka.a aVar = this.f9766s;
                PhoneNumber phoneNumber = this.f9767t;
                Date date = this.f9768u;
                this.f9763p = 1;
                obj = hVar.h(name, aVar, phoneNumber, date, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Success) {
                ProofingResponse proofingResponse = (ProofingResponse) ((ResultWrapper.Success) resultWrapper).getData();
                if (proofingResponse.isActive()) {
                    f.a.a(a.this.f9723e, "L1 - Proofing Successful_Adobe", null, 2, null);
                } else if (t.b(proofingResponse.getIppTechnicalIssue(), kotlin.coroutines.jvm.internal.b.a(true)) && proofingResponse.isIncomplete()) {
                    f.a.a(a.this.f9723e, "L1 - Proofing Fail due to IPP down_Adobe", null, 2, null);
                } else {
                    ProofingState proofingState = (ProofingState) a.this.f9722d.c().f();
                    if ((proofingState == null || (proofingProfiles = proofingState.getProofingProfiles()) == null) ? true : proofingProfiles.isEmpty()) {
                        if (a.this.f9722d.e() == 1 && a.this.f9722d.f().f() == null) {
                            a.this.f9733o.q(VerifyDobFlow.INITIAL_FAIL);
                        } else {
                            a.this.f9743y.s();
                        }
                    }
                }
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                f.a.a(a.this.f9723e, "L1 - Proofing System Error_Adobe", null, 2, null);
                a.this.j0((ResultWrapper.Error) resultWrapper, true);
            }
            return n0.f34904a;
        }

        @Override // dn.p
        public final Object invoke(m0 m0Var, vm.d dVar) {
            return ((n) 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.h repository, d9.f analyticsService, g9.l userAuthenticationRepository, fa.a myMailRepository, ka.b profileRepository) {
        super((Application) r0);
        t.g(contextService, "contextService");
        t.g(repository, "repository");
        t.g(analyticsService, "analyticsService");
        t.g(userAuthenticationRepository, "userAuthenticationRepository");
        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.f9721c = contextService;
        this.f9722d = repository;
        this.f9723e = analyticsService;
        this.f9724f = userAuthenticationRepository;
        this.f9725g = new l8.i(contextService);
        this.f9726h = new l8.d();
        l8.g gVar = new l8.g();
        this.f9727i = gVar;
        this.f9728j = gVar;
        l8.g gVar2 = new l8.g();
        this.f9729k = gVar2;
        this.f9730l = gVar2;
        l8.g gVar3 = new l8.g();
        this.f9731m = gVar3;
        this.f9732n = gVar3;
        l8.g gVar4 = new l8.g();
        this.f9733o = gVar4;
        this.f9734p = gVar4;
        f0 f0Var = new f0();
        this.f9735q = f0Var;
        this.f9736r = f0Var;
        this.f9737s = new dd.d(P(), repository, t.b(profileRepository.G().f(), Boolean.TRUE), myMailRepository, new i(), new j(), new k(), new l());
        this.f9738t = true;
        d0 d0Var = new d0();
        d0Var.r(repository.d(), new h(new c(d0Var)));
        d0Var.r(repository.i(), new h(new d(d0Var)));
        d0Var.r(repository.b(), new h(new e(d0Var)));
        d0Var.r(repository.f(), new h(new f(d0Var)));
        d0Var.r(repository.c(), new h(new g(d0Var)));
        this.f9739u = d0Var;
        this.f9740v = d0Var;
        l8.g gVar5 = new l8.g();
        this.f9741w = gVar5;
        this.f9742x = gVar5;
        l8.g gVar6 = new l8.g();
        this.f9743y = gVar6;
        this.f9744z = gVar6;
        this.A = y0.a(repository.c(), new m());
        f.a.c(analyticsService, "User-IdentityVerification", null, 2, null);
        h.a.a(this, a1.a(this), null, null, null, new C0261a(null), 7, null);
    }

    private final void m0() {
        ka.a aVar = (ka.a) this.f9722d.i().f();
        Name name = (Name) this.f9722d.d().f();
        PhoneNumber phoneNumber = (PhoneNumber) this.f9722d.b().f();
        Date date = (Date) this.f9722d.f().f();
        if (phoneNumber == null && date == null) {
            this.f9735q.q(this.f9737s.b(true));
        } else if (aVar == null || name == null) {
            j0(new ResultWrapper.Error(null, null, RepositoryError.Unknown, null, 8, null), true);
        } else {
            h.a.a(this, a1.a(this), null, null, this.f9721c.getString(yc.a0.f52095r), new n(name, aVar, phoneNumber, date, null), 3, null);
        }
    }

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

    public final void Z() {
        this.f9735q.q(dd.d.c(this.f9737s, false, 1, null));
    }

    public final a0 a0() {
        return this.f9740v;
    }

    public final a0 b0() {
        return this.f9736r;
    }

    public final a0 c0() {
        return this.f9730l;
    }

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

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

    public final a0 f0() {
        return this.f9732n;
    }

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

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

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

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

    public final void k0() {
        Map p10;
        if (this.f9724f.b() == d9.b.MY_MAIL_FLOW) {
            d9.f fVar = this.f9723e;
            p10 = q0.p(d9.e.f15943f.a("User-IdentityVerification"), c0.a("e.Var13", "mymail_verifyIdentity_l1"));
            fVar.b("User-IdentityVerification_Click_Verify_Adobe", p10);
        }
        m0();
    }

    public final void l0() {
        this.f9741w.s();
    }

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

    @Override // l8.c
    public a0 t() {
        return this.f9726h.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.f9725g.u(m0Var, context, start, str, block);
    }
}
