package we;

import android.app.Application;
import android.content.Context;
import androidx.lifecycle.a1;
import ca.canadapost.core.data.auth.model.DetailObjects;
import ca.canadapost.core.data.auth.model.RegistrationResponse;
import ca.canadapost.core.data.auth.model.RegistrationSecurityQuestion;
import ca.canadapost.core.data.auth.model.ValidationError;
import ca.canadapost.core.data.aws.model.AndroidDeviceType;
import ca.canadapost.core.data.model.Event;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import java.util.LinkedHashMap;
import java.util.List;
import l8.h;
import tp.u1;

/* loaded from: classes4.dex */
public final class g0 extends androidx.lifecycle.b implements l8.h, l8.c {
    private final androidx.lifecycle.f0 A;
    private final androidx.lifecycle.a0 B;
    private final l8.g C;
    private final androidx.lifecycle.a0 D;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(AndroidDeviceType androidDeviceType, vm.d dVar) {
            super(2, dVar);
            this.f49233r = androidDeviceType;
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f49231p;
            if (i10 == 0) {
                rm.y.b(obj);
                g9.k kVar = g0.this.f49208d;
                AndroidDeviceType androidDeviceType = this.f49233r;
                this.f49231p = 1;
                obj = kVar.a(androidDeviceType, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                rm.y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Success) {
                g0.this.A.q(new Event(kotlin.coroutines.jvm.internal.b.a(true)));
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                ResultWrapper.Error error = (ResultWrapper.Error) resultWrapper;
                String X = g0.this.X(error.getException());
                if ((X == null || X.length() == 0) || !kotlin.jvm.internal.t.b(X, "209")) {
                    g0.this.f49227w.q(new Event(kotlin.coroutines.jvm.internal.b.a(true)));
                    if (error.getError() == RepositoryError.NoNetworkError) {
                        g0.this.i0(new ResultWrapper.Error(error.getException(), error.getMessage(), error.getError(), null, 8, null), true);
                    }
                } else {
                    g0.this.C.s();
                }
            }
            return rm.n0.f34904a;
        }

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f49234p;
            if (i10 == 0) {
                rm.y.b(obj);
                g9.k kVar = g0.this.f49208d;
                this.f49234p = 1;
                obj = kVar.i(this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                rm.y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (!(resultWrapper instanceof ResultWrapper.Error)) {
                g0.this.f49229y.q(new Event(kotlin.coroutines.jvm.internal.b.a(true)));
                return rm.n0.f34904a;
            }
            ResultWrapper.Error error = (ResultWrapper.Error) resultWrapper;
            if (error.getError() == RepositoryError.NoNetworkError) {
                g0.this.i0(new ResultWrapper.Error(error.getException(), error.getMessage(), error.getError(), null, 8, null), true);
            }
            return rm.n0.f34904a;
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public g0(t7.c contextService, d9.f analyticsService, g9.k registrationRepository) {
        super((Application) r0);
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        kotlin.jvm.internal.t.g(registrationRepository, "registrationRepository");
        Context a10 = contextService.a();
        kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f49207c = contextService;
        this.f49208d = registrationRepository;
        this.f49209e = new l8.i(contextService);
        this.f49210f = new l8.d();
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0();
        this.f49211g = f0Var;
        this.f49212h = f0Var;
        this.f49213i = new androidx.lifecycle.f0();
        this.f49214j = new androidx.lifecycle.f0();
        this.f49215k = new androidx.lifecycle.f0();
        this.f49216l = new androidx.lifecycle.f0();
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0();
        this.f49217m = f0Var2;
        this.f49218n = f0Var2;
        androidx.lifecycle.f0 f0Var3 = new androidx.lifecycle.f0();
        this.f49219o = f0Var3;
        this.f49220p = f0Var3;
        Boolean bool = Boolean.FALSE;
        androidx.lifecycle.f0 f0Var4 = new androidx.lifecycle.f0(bool);
        this.f49221q = f0Var4;
        this.f49222r = f0Var4;
        androidx.lifecycle.f0 f0Var5 = new androidx.lifecycle.f0(new Event(bool));
        this.f49223s = f0Var5;
        this.f49224t = f0Var5;
        androidx.lifecycle.f0 f0Var6 = new androidx.lifecycle.f0(bool);
        this.f49225u = f0Var6;
        this.f49226v = f0Var6;
        androidx.lifecycle.f0 f0Var7 = new androidx.lifecycle.f0(new Event(bool));
        this.f49227w = f0Var7;
        this.f49228x = f0Var7;
        androidx.lifecycle.f0 f0Var8 = new androidx.lifecycle.f0(new Event(bool));
        this.f49229y = f0Var8;
        this.f49230z = f0Var8;
        androidx.lifecycle.f0 f0Var9 = new androidx.lifecycle.f0(new Event(bool));
        this.A = f0Var9;
        this.B = f0Var9;
        l8.g gVar = new l8.g();
        this.C = gVar;
        this.D = gVar;
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        String str = (String) registrationRepository.j().f();
        str = str == null ? "" : str;
        kotlin.jvm.internal.t.d(str);
        linkedHashMap.put("e.Var106", str);
        String str2 = (String) registrationRepository.e().f();
        str2 = str2 == null ? "" : str2;
        kotlin.jvm.internal.t.d(str2);
        linkedHashMap.put("e.Var107", str2);
        String str3 = (String) registrationRepository.p().f();
        String str4 = str3 != null ? str3 : "";
        kotlin.jvm.internal.t.d(str4);
        linkedHashMap.put("e.Var108", str4);
        analyticsService.c("UserSignupStep3", linkedHashMap);
        f0Var.q(contextService.getString(f.f49202w));
        f0Var6.q(bool);
        f0Var2.q(bool);
        f0Var3.q(bool);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String X(Throwable th2) {
        if (th2 != null && (th2 instanceof or.j)) {
            or.t b10 = ((or.j) th2).b();
            uq.e0 d10 = b10 != null ? b10.d() : null;
            if (d10 != null) {
                try {
                    RegistrationResponse registrationResponse = (RegistrationResponse) new com.google.gson.d().j(d10.j(), RegistrationResponse.class);
                    if (registrationResponse != null) {
                        DetailObjects detailObjects = registrationResponse.getDetailObjects();
                        List<ValidationError> validationErrors = detailObjects != null ? detailObjects.getValidationErrors() : null;
                        if (validationErrors != null && (!validationErrors.isEmpty())) {
                            return validationErrors.get(0).getCode();
                        }
                    }
                } catch (Exception e10) {
                    tr.a.f36618a.d(e10, e10.getMessage(), new Object[0]);
                    e10.printStackTrace();
                }
            }
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:10:0x0038  */
    /* JADX WARN: Removed duplicated region for block: B:14:0x0042  */
    /* JADX WARN: Removed duplicated region for block: B:17:0x0056  */
    /* JADX WARN: Removed duplicated region for block: B:21:0x0063  */
    /* JADX WARN: Removed duplicated region for block: B:22:0x002d  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0024  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final boolean l0() {
        boolean z10;
        boolean z11;
        CharSequence charSequence;
        boolean C;
        boolean C2;
        androidx.lifecycle.f0 f0Var = this.f49217m;
        Boolean bool = Boolean.FALSE;
        f0Var.q(bool);
        this.f49219o.q(bool);
        CharSequence charSequence2 = (CharSequence) this.f49215k.f();
        boolean z12 = false;
        boolean z13 = true;
        if (charSequence2 != null) {
            C2 = kotlin.text.y.C(charSequence2);
            if (!C2) {
                z10 = false;
                if (z10) {
                    z11 = true;
                } else {
                    this.f49217m.q(Boolean.TRUE);
                    z11 = false;
                }
                charSequence = (CharSequence) this.f49216l.f();
                if (charSequence != null) {
                    C = kotlin.text.y.C(charSequence);
                    if (!C) {
                        z13 = false;
                    }
                }
                if (z13) {
                    this.f49219o.q(Boolean.TRUE);
                    z11 = false;
                }
                if (kotlin.jvm.internal.t.b(this.f49221q.f(), bool)) {
                    z12 = z11;
                } else {
                    this.f49223s.q(new Event(Boolean.TRUE));
                }
                this.f49225u.q(Boolean.valueOf(z12));
                return z12;
            }
        }
        z10 = true;
        if (z10) {
        }
        charSequence = (CharSequence) this.f49216l.f();
        if (charSequence != null) {
        }
        if (z13) {
        }
        if (kotlin.jvm.internal.t.b(this.f49221q.f(), bool)) {
        }
        this.f49225u.q(Boolean.valueOf(z12));
        return z12;
    }

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

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

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

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

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

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

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

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

    public final androidx.lifecycle.f0 e0() {
        return this.f49215k;
    }

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

    public final androidx.lifecycle.f0 g0() {
        return this.f49213i;
    }

    public final androidx.lifecycle.f0 h0() {
        return this.f49214j;
    }

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

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

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

    public final void m0() {
        if (l0()) {
            AndroidDeviceType androidDeviceType = AndroidDeviceType.MOBILE;
            g9.k kVar = this.f49208d;
            Object f10 = this.f49213i.f();
            kotlin.jvm.internal.t.d(f10);
            Object f11 = this.f49215k.f();
            kotlin.jvm.internal.t.d(f11);
            Object f12 = this.f49214j.f();
            kotlin.jvm.internal.t.d(f12);
            Object f13 = this.f49216l.f();
            kotlin.jvm.internal.t.d(f13);
            kVar.h(new RegistrationSecurityQuestion((String) f10, (String) f11, (String) f12, (String) f13));
            h.a.a(this, a1.a(this), null, null, null, new a(androidDeviceType, null), 7, null);
        }
    }

    public final void n0(String position) {
        kotlin.jvm.internal.t.g(position, "position");
        this.f49213i.q(position);
    }

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

    public final void o0(String position) {
        kotlin.jvm.internal.t.g(position, "position");
        this.f49214j.q(position);
    }

    public final void p0(boolean z10) {
        this.f49221q.n(Boolean.valueOf(z10));
    }

    public final void q0() {
        h.a.a(this, a1.a(this), null, null, null, new b(null), 7, null);
    }

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

    @Override // l8.h
    public 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.f49209e.u(m0Var, context, start, str, block);
    }
}
