package ne;

import androidx.lifecycle.a0;
import androidx.lifecycle.a1;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.core.data.mymail.model.MyMailFlowArguments;
import ca.canadapost.core.data.mymail.model.MyMailStatus;
import ca.canadapost.core.data.mymail.model.MyMailSubscribeBody;
import ca.canadapost.core.data.mymail.model.Preferences;
import d9.f;
import dn.p;
import kotlin.coroutines.jvm.internal.l;
import kotlin.jvm.internal.t;
import l8.h;
import rm.n0;
import rm.y;
import tp.m0;

/* loaded from: classes4.dex */
public final class g extends yd.c {

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

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

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

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

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

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

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

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

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

    /* loaded from: classes4.dex */
    static final class a extends l implements p {

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

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

        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;
            int i10;
            f10 = wm.d.f();
            int i11 = this.f29934q;
            if (i11 == 0) {
                y.b(obj);
                MyMailStatus i12 = g.this.f29924q.i();
                MyMailStatus myMailStatus = MyMailStatus.SUBSCRIBED;
                if (i12 != myMailStatus && g.this.f29924q.i() != MyMailStatus.UNAUTHORIZED) {
                    g.this.f29927t.s();
                    return n0.f34904a;
                }
                MyMailSubscribeBody myMailSubscribeBody = new MyMailSubscribeBody(myMailStatus, new Preferences(kotlin.coroutines.jvm.internal.b.a(true), null, null, 6, null));
                fa.a aVar = g.this.f29924q;
                this.f29933p = 1;
                this.f29934q = 1;
                obj = aVar.m(myMailSubscribeBody, this);
                if (obj == f10) {
                    return f10;
                }
                i10 = 1;
            } else {
                if (i11 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                i10 = this.f29933p;
                y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Success) {
                g.this.f29924q.w(i10 != 0);
                if (t.b(g.this.f29924q.k().f(), kotlin.coroutines.jvm.internal.b.a(false))) {
                    g.this.f29929v.s();
                } else {
                    g.this.f29924q.d(false);
                    g.this.f29931x.s();
                }
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                g.this.b0((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);
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public g(t7.c contextService, g9.d sessionRepository, ka.b userRepository, d9.f analyticsService, fa.a myMailRepository) {
        super(contextService, myMailRepository, sessionRepository, userRepository, analyticsService);
        t.g(contextService, "contextService");
        t.g(sessionRepository, "sessionRepository");
        t.g(userRepository, "userRepository");
        t.g(analyticsService, "analyticsService");
        t.g(myMailRepository, "myMailRepository");
        this.f29924q = myMailRepository;
        l8.g gVar = new l8.g();
        this.f29925r = gVar;
        this.f29926s = gVar;
        l8.g gVar2 = new l8.g();
        this.f29927t = gVar2;
        this.f29928u = gVar2;
        l8.g gVar3 = new l8.g();
        this.f29929v = gVar3;
        this.f29930w = gVar3;
        l8.g gVar4 = new l8.g();
        this.f29931x = gVar4;
        this.f29932y = gVar4;
        MyMailFlowArguments myMailFlowArguments = (MyMailFlowArguments) myMailRepository.p().f();
        if (myMailFlowArguments != null) {
            if (myMailFlowArguments.getIsTncAccepted()) {
                gVar2.s();
            } else {
                f.a.c(analyticsService, "Mailbox_Automated_DropOff_Terms_and_Conditions", null, 2, null);
            }
        }
    }

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

    public final a0 n0() {
        return this.f29930w;
    }

    public final a0 o0() {
        return this.f29932y;
    }

    public final a0 p0() {
        return this.f29928u;
    }

    public final a0 q0() {
        return this.f29926s;
    }

    public final void r0() {
        if (t.b(this.f29924q.k().f(), Boolean.TRUE)) {
            this.f29924q.d(false);
        }
        this.f29931x.s();
    }

    public final void s0() {
        this.f29925r.s();
    }
}
