package xd;

import androidx.lifecycle.a0;
import androidx.lifecycle.a1;
import ca.canadapost.core.data.auth.model.UserProfile;
import ca.canadapost.core.data.model.PhoneNumber;
import ca.canadapost.core.data.model.PhoneNumberFormat;
import ca.canadapost.core.data.model.ResultWrapper;
import d9.f;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import l8.h;
import rm.n0;
import rm.y;
import tp.m0;

/* loaded from: classes4.dex */
public final class g extends xd.b {

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

    /* renamed from: o, reason: collision with root package name */
    private final e9.b f50761o;

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

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

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

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

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

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

    /* renamed from: v, reason: collision with root package name */
    private final rm.o f50768v;

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

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ t7.c f50769p;

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(t7.c cVar, g gVar) {
            super(0);
            this.f50769p = cVar;
            this.f50770q = gVar;
        }

        @Override // dn.a
        public final String invoke() {
            return this.f50769p.d(ld.m.f27973b0, this.f50770q.k0());
        }
    }

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

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

        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.f50771p;
            if (i10 == 0) {
                y.b(obj);
                ka.b bVar = g.this.f50762p;
                this.f50771p = 1;
                if (bVar.D(this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            g.this.f50766t.q(kotlin.coroutines.jvm.internal.b.a(g.this.f50765s.length() > 0));
            return n0.f34904a;
        }

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

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

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

        /* renamed from: q, reason: collision with root package name */
        /* synthetic */ Object f50774q;

        /* renamed from: s, reason: collision with root package name */
        int f50776s;

        c(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f50774q = obj;
            this.f50776s |= Integer.MIN_VALUE;
            return g.this.g0(null, this);
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public g(d9.f analyticsService, e9.b adobeAnalytics, t7.c contextService, ka.b repository, g9.l userAuthenticationRepository, String phoneNumber) {
        super(contextService);
        rm.o a10;
        t.g(analyticsService, "analyticsService");
        t.g(adobeAnalytics, "adobeAnalytics");
        t.g(contextService, "contextService");
        t.g(repository, "repository");
        t.g(userAuthenticationRepository, "userAuthenticationRepository");
        t.g(phoneNumber, "phoneNumber");
        this.f50760n = analyticsService;
        this.f50761o = adobeAnalytics;
        this.f50762p = repository;
        this.f50763q = userAuthenticationRepository;
        this.f50764r = phoneNumber;
        UserProfile userProfile = (UserProfile) repository.a().f();
        String mfaPhone = userProfile != null ? userProfile.getMfaPhone() : null;
        this.f50765s = mfaPhone == null ? "" : mfaPhone;
        l8.g gVar = new l8.g();
        this.f50766t = gVar;
        this.f50767u = gVar;
        a10 = rm.q.a(new a(contextService, this));
        this.f50768v = a10;
        f.a.c(analyticsService, "2SV-OneTimeAccessCode", null, 2, null);
        super.c0();
    }

    private final void m0(String str, String str2) {
        this.f50760n.b(str, d9.e.f15943f.a("2SV-OneTimeAccessCode"));
        f.a.a(this.f50761o, str2, null, 2, null);
    }

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

    @Override // xd.b
    public Object S(vm.d dVar) {
        return this.f50763q.d(this.f50764r, dVar);
    }

    @Override // xd.b
    public String V() {
        Object value = this.f50768v.getValue();
        t.f(value, "getValue(...)");
        return (String) value;
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x004d  */
    /* JADX WARN: Removed duplicated region for block: B:15:0x0056  */
    /* JADX WARN: Removed duplicated region for block: B:18:0x0035  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0023  */
    @Override // xd.b
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object g0(String str, vm.d dVar) {
        c cVar;
        Object f10;
        int i10;
        ResultWrapper resultWrapper;
        if (dVar instanceof c) {
            cVar = (c) dVar;
            int i11 = cVar.f50776s;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                cVar.f50776s = i11 - Integer.MIN_VALUE;
                Object obj = cVar.f50774q;
                f10 = wm.d.f();
                i10 = cVar.f50776s;
                if (i10 != 0) {
                    y.b(obj);
                    g9.l lVar = this.f50763q;
                    String str2 = this.f50764r;
                    cVar.f50773p = this;
                    cVar.f50776s = 1;
                    obj = lVar.a(str2, str, cVar);
                    if (obj == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    this = (g) cVar.f50773p;
                    y.b(obj);
                }
                resultWrapper = (ResultWrapper) obj;
                if (resultWrapper instanceof ResultWrapper.Success) {
                    this.m0("2SV_AccessCodeFailure_Adobe", "2SV_AccessCodeFailure_Adobe");
                } else {
                    this.m0("2SV_AccessCodeComplete_Adobe", "2SV_AccessCodeComplete_Adobe");
                    this.n0();
                }
                return resultWrapper;
            }
        }
        cVar = new c(dVar);
        Object obj2 = cVar.f50774q;
        f10 = wm.d.f();
        i10 = cVar.f50776s;
        if (i10 != 0) {
        }
        resultWrapper = (ResultWrapper) obj2;
        if (resultWrapper instanceof ResultWrapper.Success) {
        }
        return resultWrapper;
    }

    public final String k0() {
        return String.valueOf(PhoneNumber.INSTANCE.parsePhoneNumber(this.f50764r, PhoneNumberFormat.FORMAT2));
    }

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