package sd;

import androidx.lifecycle.a0;
import androidx.lifecycle.a1;
import androidx.lifecycle.f0;
import androidx.lifecycle.z0;
import ca.canadapost.core.data.auth.model.UsernamePasswordRecoveryResponse;
import ca.canadapost.core.data.model.ResultWrapper;
import d9.f;
import kotlin.jvm.internal.t;
import l8.h;
import rm.n0;
import rm.y;
import tp.m0;
import tp.o0;
import tp.u1;

/* loaded from: classes4.dex */
public final class g extends z0 implements l8.h, l8.c {

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

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

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

    /* renamed from: e, reason: collision with root package name */
    private final ld.n f35623e;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f35638p;
            if (i10 == 0) {
                y.b(obj);
                g9.l lVar = g.this.f35622d;
                String str = (String) g.this.U().f();
                if (str == null) {
                    str = "";
                }
                String str2 = (String) g.this.X().f();
                String str3 = str2 != null ? str2 : "";
                this.f35638p = 1;
                obj = lVar.l(str, str3, 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) {
                ResultWrapper.Success success = (ResultWrapper.Success) resultWrapper;
                String secretQuestion = ((UsernamePasswordRecoveryResponse) success.getData()).getSecretQuestion();
                if (secretQuestion == null || secretQuestion.length() == 0) {
                    String phoneNumber = ((UsernamePasswordRecoveryResponse) success.getData()).getPhoneNumber();
                    if (phoneNumber == null || phoneNumber.length() == 0) {
                        g.this.f35634p.s();
                    } else {
                        g.this.f35623e.X(((UsernamePasswordRecoveryResponse) success.getData()).getPhoneNumber());
                        g.this.f35632n.q(kotlin.coroutines.jvm.internal.b.a(true));
                    }
                } else {
                    g.this.f35623e.Z(((UsernamePasswordRecoveryResponse) success.getData()).getSecretQuestion());
                    g.this.f35632n.q(kotlin.coroutines.jvm.internal.b.a(false));
                }
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                g.this.a0((ResultWrapper.Error) resultWrapper, true);
            }
            return n0.f34904a;
        }

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

    public g(t7.c contextService, d9.f analyticsService, g9.l authRepository, ld.n sharedViewModel) {
        t.g(contextService, "contextService");
        t.g(analyticsService, "analyticsService");
        t.g(authRepository, "authRepository");
        t.g(sharedViewModel, "sharedViewModel");
        this.f35620b = contextService;
        this.f35621c = analyticsService;
        this.f35622d = authRepository;
        this.f35623e = sharedViewModel;
        this.f35624f = new l8.i(contextService);
        this.f35625g = new l8.d();
        f0 f0Var = new f0();
        this.f35626h = f0Var;
        this.f35627i = f0Var;
        f0 f0Var2 = new f0();
        this.f35628j = f0Var2;
        this.f35629k = f0Var2;
        f0 f0Var3 = new f0();
        this.f35630l = f0Var3;
        this.f35631m = f0Var3;
        l8.g gVar = new l8.g();
        this.f35632n = gVar;
        this.f35633o = gVar;
        l8.g gVar2 = new l8.g();
        this.f35634p = gVar2;
        this.f35635q = gVar2;
        this.f35636r = new f0();
        this.f35637s = new f0();
        f.a.c(analyticsService, "UserForgotUNStep1", null, 2, null);
        f0Var3.q(Boolean.FALSE);
    }

    private final void T() {
        boolean z10;
        boolean z11 = false;
        if (qa.d.i((String) this.f35636r.f())) {
            this.f35626h.q(null);
            z10 = true;
        } else {
            this.f35626h.q(this.f35620b.getString(ld.m.f28000p));
            z10 = false;
        }
        if (qa.d.l((String) this.f35637s.f())) {
            this.f35628j.q(null);
            z11 = z10;
        } else {
            this.f35628j.q(this.f35620b.getString(ld.m.f28002q));
        }
        this.f35630l.q(Boolean.valueOf(z11));
    }

    private final void c0() {
        h.a.a(this, a1.a(this), null, null, null, new a(null), 7, null);
    }

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

    public final f0 U() {
        return this.f35636r;
    }

    public final a0 V() {
        return this.f35627i;
    }

    public final a0 W() {
        return this.f35633o;
    }

    public final f0 X() {
        return this.f35637s;
    }

    public final a0 Y() {
        return this.f35629k;
    }

    public final a0 Z() {
        return this.f35635q;
    }

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

    public final void b0() {
        T();
        Boolean bool = (Boolean) this.f35630l.f();
        if (bool == null || !bool.booleanValue()) {
            return;
        }
        this.f35623e.V((String) this.f35636r.f());
        this.f35623e.Y((String) this.f35637s.f());
        c0();
    }

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

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

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