package cc;

import android.app.Application;
import android.content.Context;
import ca.canadapost.core.data.auth.model.ProofingState;
import ca.canadapost.core.data.model.AMSCheckSteps;
import ca.canadapost.core.data.model.Event;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.core.data.profile.model.AMSPrerequisitesResponse;
import java.util.Arrays;
import l8.h;

/* loaded from: classes4.dex */
public final class x2 extends androidx.lifecycle.b implements l8.h, l8.c {

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

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

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

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

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

    /* renamed from: h, reason: collision with root package name */
    private final p9.h f11864h;

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

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

    /* renamed from: k, reason: collision with root package name */
    private final androidx.lifecycle.f0 f11867k;

    /* renamed from: l, reason: collision with root package name */
    private final androidx.lifecycle.a0 f11868l;

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

    /* renamed from: n, reason: collision with root package name */
    private final androidx.lifecycle.a0 f11870n;

    /* renamed from: o, reason: collision with root package name */
    private final androidx.lifecycle.f0 f11871o;

    /* renamed from: p, reason: collision with root package name */
    private final androidx.lifecycle.a0 f11872p;

    /* renamed from: q, reason: collision with root package name */
    private AMSPrerequisitesResponse f11873q;

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

    /* renamed from: s, reason: collision with root package name */
    private final androidx.lifecycle.a0 f11875s;

    /* renamed from: t, reason: collision with root package name */
    private final androidx.lifecycle.a0 f11876t;

    /* renamed from: u, reason: collision with root package name */
    private final androidx.lifecycle.a0 f11877u;

    /* renamed from: v, reason: collision with root package name */
    private final androidx.lifecycle.g0 f11878v;

    /* loaded from: classes4.dex */
    public /* synthetic */ class a {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f11879a;

        static {
            int[] iArr = new int[AMSCheckSteps.values().length];
            try {
                iArr[AMSCheckSteps.L2.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[AMSCheckSteps.L1AUTH.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            f11879a = iArr;
        }
    }

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

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

        b() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final String invoke(ka.a address) {
            kotlin.jvm.internal.t.g(address, "address");
            kotlin.jvm.internal.u0 u0Var = kotlin.jvm.internal.u0.f26205a;
            Object[] objArr = new Object[2];
            String c10 = address.c();
            String str = "";
            if (c10 == null) {
                c10 = "";
            }
            objArr[0] = c10;
            String d10 = address.d();
            if (!(d10 == null || d10.length() == 0)) {
                str = ("\n") + address.d();
            }
            objArr[1] = str;
            String format = String.format("%s %s", Arrays.copyOf(objArr, 2));
            kotlin.jvm.internal.t.f(format, "format(...)");
            return format;
        }
    }

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

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

        c() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final String invoke(ka.a address) {
            kotlin.jvm.internal.t.g(address, "address");
            kotlin.jvm.internal.u0 u0Var = kotlin.jvm.internal.u0.f26205a;
            String format = String.format("%s, %s, %s, %s", Arrays.copyOf(new Object[]{address.a(), address.f(), address.e(), address.b()}, 4));
            kotlin.jvm.internal.t.f(format, "format(...)");
            return format;
        }
    }

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

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

        d() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final androidx.lifecycle.a0 invoke(AMSCheckSteps aMSCheckSteps) {
            return new androidx.lifecycle.f0(new Event(aMSCheckSteps));
        }
    }

    /* loaded from: classes4.dex */
    static final class e extends kotlin.coroutines.jvm.internal.l implements dn.p {

        /* renamed from: p, reason: collision with root package name */
        Object f11883p;

        /* renamed from: q, reason: collision with root package name */
        int f11884q;

        /* loaded from: classes4.dex */
        public /* synthetic */ class a {

            /* renamed from: a, reason: collision with root package name */
            public static final /* synthetic */ int[] f11886a;

            static {
                int[] iArr = new int[AMSCheckSteps.values().length];
                try {
                    iArr[AMSCheckSteps.L1AUTH.ordinal()] = 1;
                } catch (NoSuchFieldError unused) {
                }
                try {
                    iArr[AMSCheckSteps.L2.ordinal()] = 2;
                } catch (NoSuchFieldError unused2) {
                }
                try {
                    iArr[AMSCheckSteps.MYMAIL.ordinal()] = 3;
                } catch (NoSuchFieldError unused3) {
                }
                f11886a = iArr;
            }
        }

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            x2 x2Var;
            Object w10;
            f10 = wm.d.f();
            int i10 = this.f11884q;
            if (i10 == 0) {
                rm.y.b(obj);
                ka.a aVar = (ka.a) x2.this.f11860d.k().f();
                if (aVar != null) {
                    x2Var = x2.this;
                    ka.a aVar2 = new ka.a(aVar.c(), aVar.d(), aVar.a(), aVar.f(), aVar.e(), aVar.b());
                    ka.b bVar = x2Var.f11860d;
                    this.f11883p = x2Var;
                    this.f11884q = 1;
                    w10 = bVar.w(aVar2, this);
                    if (w10 == f10) {
                        return f10;
                    }
                }
                return rm.n0.f34904a;
            }
            if (i10 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            x2 x2Var2 = (x2) this.f11883p;
            rm.y.b(obj);
            x2Var = x2Var2;
            w10 = obj;
            ResultWrapper.Error error = (ResultWrapper.Error) w10;
            if (error == null) {
                AMSPrerequisitesResponse aMSPrerequisitesResponse = x2Var.f11873q;
                if (aMSPrerequisitesResponse != null) {
                    if (kotlin.jvm.internal.t.b(aMSPrerequisitesResponse.getSnfStatus(), kotlin.coroutines.jvm.internal.b.a(false)) || kotlin.jvm.internal.t.b(aMSPrerequisitesResponse.getTnc(), kotlin.coroutines.jvm.internal.b.a(false))) {
                        x2Var.f11869m.s();
                    } else {
                        x2Var.f11874r.s();
                    }
                }
            } else if (error.getAdditionalInfo() instanceof AMSCheckSteps) {
                Object additionalInfo = error.getAdditionalInfo();
                kotlin.jvm.internal.t.e(additionalInfo, "null cannot be cast to non-null type ca.canadapost.core.data.model.AMSCheckSteps");
                AMSCheckSteps aMSCheckSteps = (AMSCheckSteps) additionalInfo;
                int i11 = a.f11886a[aMSCheckSteps.ordinal()];
                if (i11 == 1 || i11 == 2) {
                    x2Var.f11861e.g();
                    x2Var.f11862f.g();
                    x2Var.f11871o.q(aMSCheckSteps);
                } else if (i11 == 3) {
                    x2Var.f11871o.q(aMSCheckSteps);
                }
            } else {
                w8.g0 g0Var = w8.g0.f40967a;
                Context a10 = x2Var.f11863g.a();
                kotlin.jvm.internal.t.f(a10, "getApplicationContext(...)");
                if (g0Var.a(a10)) {
                    x2Var.h0(new ResultWrapper.Error(null, null, RepositoryError.Unknown, null, 8, null), true);
                } else {
                    x2Var.h0(new ResultWrapper.Error(null, null, RepositoryError.NoNetworkError, null, 8, null), true);
                }
            }
            return rm.n0.f34904a;
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public x2(fa.a myMailRepository, ka.b repository, g9.h l1AuthRepository, g9.i l2Repository, t7.c contextService, p9.h featureFlagRepository) {
        super((Application) r0);
        kotlin.jvm.internal.t.g(myMailRepository, "myMailRepository");
        kotlin.jvm.internal.t.g(repository, "repository");
        kotlin.jvm.internal.t.g(l1AuthRepository, "l1AuthRepository");
        kotlin.jvm.internal.t.g(l2Repository, "l2Repository");
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(featureFlagRepository, "featureFlagRepository");
        Context a10 = contextService.a();
        kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f11859c = myMailRepository;
        this.f11860d = repository;
        this.f11861e = l1AuthRepository;
        this.f11862f = l2Repository;
        this.f11863g = contextService;
        this.f11864h = featureFlagRepository;
        this.f11865i = new l8.i(contextService);
        this.f11866j = new l8.d();
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0(new Event(Boolean.FALSE));
        this.f11867k = f0Var;
        this.f11868l = f0Var;
        l8.g gVar = new l8.g();
        this.f11869m = gVar;
        this.f11870n = gVar;
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0();
        this.f11871o = f0Var2;
        this.f11872p = androidx.lifecycle.y0.b(f0Var2, d.f11882p);
        l8.g gVar2 = new l8.g();
        this.f11874r = gVar2;
        this.f11875s = gVar2;
        this.f11876t = androidx.lifecycle.y0.a(repository.k(), b.f11880p);
        this.f11877u = androidx.lifecycle.y0.a(repository.k(), c.f11881p);
        androidx.lifecycle.g0 g0Var = new androidx.lifecycle.g0() { // from class: cc.w2
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                x2.Z(x2.this, (AMSPrerequisitesResponse) obj);
            }
        };
        repository.J().k(g0Var);
        this.f11878v = g0Var;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void Z(x2 this$0, AMSPrerequisitesResponse aMSPrerequisitesResponse) {
        kotlin.jvm.internal.t.g(this$0, "this$0");
        if (aMSPrerequisitesResponse != null) {
            this$0.f11873q = aMSPrerequisitesResponse;
        }
    }

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

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.lifecycle.z0
    public void O() {
        this.f11860d.J().o(this.f11878v);
        super.O();
    }

    public final androidx.lifecycle.a0 a0() {
        return this.f11876t;
    }

    public final androidx.lifecycle.a0 b0() {
        return this.f11877u;
    }

    public final androidx.lifecycle.a0 c0() {
        return this.f11875s;
    }

    public final fa.a d0() {
        return this.f11859c;
    }

    public final androidx.lifecycle.a0 e0() {
        return this.f11872p;
    }

    public final androidx.lifecycle.a0 f0() {
        return this.f11868l;
    }

    public final androidx.lifecycle.a0 g0() {
        return this.f11870n;
    }

    public void h0(ResultWrapper.Error error, boolean z10) {
        kotlin.jvm.internal.t.g(error, "error");
        this.f11866j.a(error, z10);
    }

    public final void i0() {
        h.a.a(this, androidx.lifecycle.a1.a(this), null, null, this.f11863g.getString(ob.l.I2), new e(null), 3, null);
    }

    public final void j0() {
        ka.a aVar = (ka.a) this.f11860d.k().f();
        if (aVar != null) {
            this.f11860d.j(new ka.a(aVar.c(), aVar.d(), aVar.a(), aVar.f(), aVar.e(), aVar.b()));
            this.f11867k.q(new Event(Boolean.TRUE));
        }
    }

    public final void k0() {
        AMSPrerequisitesResponse aMSPrerequisitesResponse;
        AMSCheckSteps aMSCheckSteps = (AMSCheckSteps) this.f11871o.f();
        if (aMSCheckSteps != null) {
            int i10 = a.f11879a[aMSCheckSteps.ordinal()];
            if (i10 == 1) {
                ProofingState proofingState = (ProofingState) this.f11862f.c().f();
                boolean isL2Authenticated = proofingState != null ? proofingState.isL2Authenticated() : false;
                AMSPrerequisitesResponse aMSPrerequisitesResponse2 = this.f11873q;
                if (aMSPrerequisitesResponse2 != null) {
                    if (!isL2Authenticated) {
                        this.f11874r.s();
                        return;
                    }
                    Object f10 = this.f11859c.s().f();
                    Boolean bool = Boolean.TRUE;
                    if (kotlin.jvm.internal.t.b(f10, bool) && kotlin.jvm.internal.t.b(aMSPrerequisitesResponse2.getAddrStatus(), bool)) {
                        this.f11871o.q(AMSCheckSteps.MYMAIL);
                        return;
                    } else {
                        this.f11874r.s();
                        return;
                    }
                }
                return;
            }
            if (i10 == 2 && (aMSPrerequisitesResponse = this.f11873q) != null) {
                Boolean l1AuthStatus = aMSPrerequisitesResponse.getL1AuthStatus();
                Boolean bool2 = Boolean.FALSE;
                if (kotlin.jvm.internal.t.b(l1AuthStatus, bool2)) {
                    this.f11874r.s();
                    return;
                }
                Object f11 = this.f11859c.s().f();
                Boolean bool3 = Boolean.TRUE;
                if (kotlin.jvm.internal.t.b(f11, bool3) && kotlin.jvm.internal.t.b(aMSPrerequisitesResponse.getL1AuthStatus(), bool3) && kotlin.jvm.internal.t.b(aMSPrerequisitesResponse.getAddrStatus(), bool3)) {
                    this.f11871o.q(AMSCheckSteps.MYMAIL);
                } else if (kotlin.jvm.internal.t.b(aMSPrerequisitesResponse.getSnfStatus(), bool2) || kotlin.jvm.internal.t.b(aMSPrerequisitesResponse.getTnc(), bool2)) {
                    this.f11869m.s();
                } else {
                    this.f11874r.s();
                }
            }
        }
    }

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

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

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