package fa;

import androidx.lifecycle.a0;
import androidx.lifecycle.f0;
import ca.canadapost.core.data.aws.model.CategoryEnum;
import ca.canadapost.core.data.aws.model.SubscriptionItem;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.core.data.mymail.api.IMyMailAdApi;
import ca.canadapost.core.data.mymail.api.IMyMailApi;
import ca.canadapost.core.data.mymail.api.IMyMailTncApi;
import ca.canadapost.core.data.mymail.model.AddressEligibilityBody;
import ca.canadapost.core.data.mymail.model.AddressEligibilityResponse;
import ca.canadapost.core.data.mymail.model.CaslOptedBody;
import ca.canadapost.core.data.mymail.model.ImageDimensions;
import ca.canadapost.core.data.mymail.model.MailPieceKt;
import ca.canadapost.core.data.mymail.model.MyMailFlowArguments;
import ca.canadapost.core.data.mymail.model.MyMailHolidayPersist;
import ca.canadapost.core.data.mymail.model.MyMailHolidayRequestParams;
import ca.canadapost.core.data.mymail.model.MyMailHolidayResponse;
import ca.canadapost.core.data.mymail.model.MyMailNotificationRequest;
import ca.canadapost.core.data.mymail.model.MyMailStatus;
import ca.canadapost.core.data.mymail.model.MyMailSubscribeBody;
import ca.canadapost.core.data.mymail.model.MyMailSubscriptionResponse;
import ca.canadapost.core.data.mymail.model.MyMailTncResponse;
import ca.canadapost.core.data.mymail.model.Preferences;
import java.util.List;
import kotlin.jvm.internal.t;
import rm.n0;
import rm.y;

/* loaded from: classes.dex */
public final class b implements fa.a {

    /* renamed from: a, reason: collision with root package name */
    private final IMyMailApi f17985a;

    /* renamed from: b, reason: collision with root package name */
    private final IMyMailAdApi f17986b;

    /* renamed from: c, reason: collision with root package name */
    private final IMyMailTncApi f17987c;

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

    /* renamed from: e, reason: collision with root package name */
    private final j9.c f17989e;

    /* renamed from: f, reason: collision with root package name */
    private final ca.a f17990f;

    /* renamed from: g, reason: collision with root package name */
    private final ja.d f17991g;

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

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

    /* renamed from: j, reason: collision with root package name */
    private long f17994j;

    /* renamed from: k, reason: collision with root package name */
    private ResultWrapper f17995k;

    /* renamed from: l, reason: collision with root package name */
    private ResultWrapper f17996l;

    /* renamed from: m, reason: collision with root package name */
    private MyMailHolidayRequestParams f17997m;

    /* renamed from: n, reason: collision with root package name */
    private ResultWrapper f17998n;

    /* renamed from: o, reason: collision with root package name */
    private MyMailStatus f17999o;

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

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

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

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

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

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

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

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

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

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

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

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

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

        /* renamed from: r, reason: collision with root package name */
        /* synthetic */ Object f18012r;

        /* renamed from: t, reason: collision with root package name */
        int f18014t;

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f18012r = obj;
            this.f18014t |= Integer.MIN_VALUE;
            return b.this.c(null, this);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: fa.b$b, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public static final class C0394b extends kotlin.coroutines.jvm.internal.d {

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

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

        /* renamed from: r, reason: collision with root package name */
        /* synthetic */ Object f18017r;

        /* renamed from: t, reason: collision with root package name */
        int f18019t;

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f18017r = obj;
            this.f18019t |= Integer.MIN_VALUE;
            return b.this.l(this);
        }
    }

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f18021q = obj;
            this.f18023s |= Integer.MIN_VALUE;
            return b.this.f(this);
        }
    }

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f18025q = obj;
            this.f18027s |= Integer.MIN_VALUE;
            return b.this.e(this);
        }
    }

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

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

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

        /* renamed from: r, reason: collision with root package name */
        /* synthetic */ Object f18030r;

        /* renamed from: t, reason: collision with root package name */
        int f18032t;

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

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

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

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

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

        /* renamed from: r, reason: collision with root package name */
        /* synthetic */ Object f18035r;

        /* renamed from: t, reason: collision with root package name */
        int f18037t;

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f18035r = obj;
            this.f18037t |= Integer.MIN_VALUE;
            return b.this.m(null, this);
        }
    }

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f18039q = obj;
            this.f18041s |= Integer.MIN_VALUE;
            return b.this.v(null, false, this);
        }
    }

    public b(IMyMailApi myMailApi, IMyMailAdApi myMailAdApi, IMyMailTncApi myMailTncApi, g9.d sessionRepository, j9.c awsPushService, ca.a languageService, ja.d sharedPreferencesService) {
        t.g(myMailApi, "myMailApi");
        t.g(myMailAdApi, "myMailAdApi");
        t.g(myMailTncApi, "myMailTncApi");
        t.g(sessionRepository, "sessionRepository");
        t.g(awsPushService, "awsPushService");
        t.g(languageService, "languageService");
        t.g(sharedPreferencesService, "sharedPreferencesService");
        this.f17985a = myMailApi;
        this.f17986b = myMailAdApi;
        this.f17987c = myMailTncApi;
        this.f17988d = sessionRepository;
        this.f17989e = awsPushService;
        this.f17990f = languageService;
        this.f17991g = sharedPreferencesService;
        f0 f0Var = new f0();
        this.f17992h = f0Var;
        this.f17993i = f0Var;
        f0 f0Var2 = new f0(new MyMailFlowArguments(null, false, 3, null));
        this.f18000p = f0Var2;
        this.f18001q = f0Var2;
        Boolean bool = Boolean.FALSE;
        f0 f0Var3 = new f0(bool);
        this.f18002r = f0Var3;
        this.f18003s = f0Var3;
        f0 f0Var4 = new f0(bool);
        this.f18004t = f0Var4;
        this.f18005u = f0Var4;
        f0 f0Var5 = new f0(bool);
        this.f18006v = f0Var5;
        this.f18007w = f0Var5;
        f0 f0Var6 = new f0(bool);
        this.f18008x = f0Var6;
        this.f18009y = f0Var6;
    }

    private final void D() {
        MyMailFlowArguments myMailFlowArguments = (MyMailFlowArguments) this.f18000p.f();
        if (myMailFlowArguments != null) {
            myMailFlowArguments.setTncAccepted(false);
        }
        MyMailFlowArguments myMailFlowArguments2 = (MyMailFlowArguments) this.f18000p.f();
        if (myMailFlowArguments2 == null) {
            return;
        }
        myMailFlowArguments2.setHasAddressSupport(Boolean.FALSE);
    }

    private final String E() {
        String g10 = this.f17988d.g();
        return g10 == null ? "" : g10;
    }

    private final boolean G() {
        String h10 = this.f17990f.h();
        t.f(h10, "getLanguageCountry(...)");
        if (t.b(h10, this.f17991g.getString("LANGUAGE_COUNTRY_CODE_MYMAIL", ""))) {
            return false;
        }
        this.f17991g.putString("LANGUAGE_COUNTRY_CODE_MYMAIL", h10);
        return true;
    }

    private final boolean H() {
        return this.f17995k != null && System.currentTimeMillis() - this.f17994j < 30000;
    }

    @Override // fa.a
    public Object B(MyMailNotificationRequest myMailNotificationRequest, vm.d dVar) {
        return this.f17985a.getMyMailNotifications(E(), myMailNotificationRequest.getPageSize(), myMailNotificationRequest.getPageNumber(), myMailNotificationRequest.getStartDate(), myMailNotificationRequest.getDaySpan(), dVar);
    }

    @Override // fa.a
    public Object C(vm.d dVar) {
        tr.a.f36618a.a("AWS-Push", "1.Unsubscribing from MY Mail Push");
        this.f17989e.b(new SubscriptionItem("MMID_" + E(), CategoryEnum.mailManager, "mailManager description"), true);
        return n0.f34904a;
    }

    @Override // fa.a
    /* renamed from: F, reason: merged with bridge method [inline-methods] */
    public f0 A() {
        return this.f17993i;
    }

    @Override // fa.a
    public Object a(vm.d dVar) {
        Object f10;
        j();
        z(MyMailStatus.LOGGED_OUT);
        D();
        Object C = C(dVar);
        f10 = wm.d.f();
        return C == f10 ? C : n0.f34904a;
    }

    @Override // fa.a
    public Object b(List list, vm.d dVar) {
        return this.f17986b.fetchMyMailCommercials(E(), list, dVar);
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x00b0  */
    /* JADX WARN: Removed duplicated region for block: B:18:0x003d  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0025  */
    @Override // fa.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object c(MyMailHolidayRequestParams myMailHolidayRequestParams, vm.d dVar) {
        a aVar;
        Object f10;
        int i10;
        ResultWrapper resultWrapper;
        if (dVar instanceof a) {
            aVar = (a) dVar;
            int i11 = aVar.f18014t;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                aVar.f18014t = i11 - Integer.MIN_VALUE;
                Object obj = aVar.f18012r;
                f10 = wm.d.f();
                i10 = aVar.f18014t;
                if (i10 != 0) {
                    y.b(obj);
                    if (this.f17998n == null) {
                        MyMailHolidayPersist myMailHolidayPersist = (MyMailHolidayPersist) qa.d.p(this.f17991g.getString("MY_MAIL_HOLIDAY_CACHE_KEY", null), MyMailHolidayPersist.class);
                        if (t.b(myMailHolidayPersist != null ? myMailHolidayPersist.getMyMailHolidayRequestParams() : null, myMailHolidayRequestParams) && myMailHolidayPersist.getMyMailHolidayResponse() != null) {
                            this.f17997m = myMailHolidayPersist.getMyMailHolidayRequestParams();
                            this.f17998n = new ResultWrapper.Success(myMailHolidayPersist.getMyMailHolidayResponse());
                        }
                    }
                    if (t.b(this.f17997m, myMailHolidayRequestParams) && this.f17998n != null) {
                        ResultWrapper resultWrapper2 = this.f17998n;
                        t.e(resultWrapper2, "null cannot be cast to non-null type ca.canadapost.core.data.model.ResultWrapper<ca.canadapost.core.data.mymail.model.MyMailHolidayResponse>");
                        return resultWrapper2;
                    }
                    IMyMailApi iMyMailApi = this.f17985a;
                    String date = myMailHolidayRequestParams.getDate();
                    String postalCode = myMailHolidayRequestParams.getPostalCode();
                    String province = myMailHolidayRequestParams.getProvince();
                    aVar.f18010p = this;
                    aVar.f18011q = myMailHolidayRequestParams;
                    aVar.f18014t = 1;
                    obj = iMyMailApi.getMyMailHolidays(date, postalCode, province, aVar);
                    if (obj == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    myMailHolidayRequestParams = (MyMailHolidayRequestParams) aVar.f18011q;
                    this = (b) aVar.f18010p;
                    y.b(obj);
                }
                resultWrapper = (ResultWrapper) obj;
                if (resultWrapper instanceof ResultWrapper.Success) {
                    this.f17997m = myMailHolidayRequestParams;
                    this.f17998n = resultWrapper;
                    this.f17991g.putString("MY_MAIL_HOLIDAY_CACHE_KEY", qa.d.s(new MyMailHolidayPersist(myMailHolidayRequestParams, (MyMailHolidayResponse) ((ResultWrapper.Success) resultWrapper).getData())));
                }
                return resultWrapper;
            }
        }
        aVar = new a(dVar);
        Object obj2 = aVar.f18012r;
        f10 = wm.d.f();
        i10 = aVar.f18014t;
        if (i10 != 0) {
        }
        resultWrapper = (ResultWrapper) obj2;
        if (resultWrapper instanceof ResultWrapper.Success) {
        }
        return resultWrapper;
    }

    @Override // fa.a
    public void d(boolean z10) {
        this.f18004t.q(Boolean.valueOf(z10));
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0035  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0023  */
    @Override // fa.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object e(vm.d dVar) {
        d dVar2;
        Object f10;
        int i10;
        if (dVar instanceof d) {
            dVar2 = (d) dVar;
            int i11 = dVar2.f18027s;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                dVar2.f18027s = i11 - Integer.MIN_VALUE;
                Object obj = dVar2.f18025q;
                f10 = wm.d.f();
                i10 = dVar2.f18027s;
                if (i10 != 0) {
                    y.b(obj);
                    tr.a.f36618a.a("AWS-Push", "1.Subscribing for MY Mail Push");
                    if (G()) {
                        dVar2.f18024p = this;
                        dVar2.f18027s = 1;
                        if (C(dVar2) == f10) {
                            return f10;
                        }
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    this = (b) dVar2.f18024p;
                    y.b(obj);
                }
                this.f17989e.e(new SubscriptionItem("MMID_" + this.E(), CategoryEnum.mailManager, "mailManager description"), true);
                return n0.f34904a;
            }
        }
        dVar2 = new d(dVar);
        Object obj2 = dVar2.f18025q;
        f10 = wm.d.f();
        i10 = dVar2.f18027s;
        if (i10 != 0) {
        }
        this.f17989e.e(new SubscriptionItem("MMID_" + this.E(), CategoryEnum.mailManager, "mailManager description"), true);
        return n0.f34904a;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0035  */
    /* JADX WARN: Removed duplicated region for block: B:9:0x0023  */
    @Override // fa.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object f(vm.d dVar) {
        c cVar;
        Object f10;
        int i10;
        try {
            if (dVar instanceof c) {
                cVar = (c) dVar;
                int i11 = cVar.f18023s;
                if ((i11 & Integer.MIN_VALUE) != 0) {
                    cVar.f18023s = i11 - Integer.MIN_VALUE;
                    Object obj = cVar.f18021q;
                    f10 = wm.d.f();
                    i10 = cVar.f18023s;
                    if (i10 != 0) {
                        y.b(obj);
                        MyMailTncResponse myMailTncResponse = (MyMailTncResponse) this.f17992h.f();
                        if (myMailTncResponse != null) {
                            return new ResultWrapper.Success(myMailTncResponse);
                        }
                        IMyMailTncApi iMyMailTncApi = this.f17987c;
                        cVar.f18020p = this;
                        cVar.f18023s = 1;
                        obj = iMyMailTncApi.getMyMailTncInfo(cVar);
                        if (obj == f10) {
                            return f10;
                        }
                    } else {
                        if (i10 != 1) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        this = (b) cVar.f18020p;
                        y.b(obj);
                    }
                    MyMailTncResponse myMailTncResponse2 = (MyMailTncResponse) obj;
                    this.f17992h.n(myMailTncResponse2);
                    return new ResultWrapper.Success(myMailTncResponse2);
                }
            }
            if (i10 != 0) {
            }
            MyMailTncResponse myMailTncResponse22 = (MyMailTncResponse) obj;
            this.f17992h.n(myMailTncResponse22);
            return new ResultWrapper.Success(myMailTncResponse22);
        } catch (Exception e10) {
            return new ResultWrapper.Error(e10, "Error while getting Response", RepositoryError.ServiceError, null, 8, null);
        }
        cVar = new c(dVar);
        Object obj2 = cVar.f18021q;
        f10 = wm.d.f();
        i10 = cVar.f18023s;
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0057  */
    /* JADX WARN: Removed duplicated region for block: B:21:0x003a  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0023  */
    @Override // fa.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object g(MyMailSubscribeBody myMailSubscribeBody, vm.d dVar) {
        e eVar;
        Object f10;
        int i10;
        ResultWrapper resultWrapper;
        if (dVar instanceof e) {
            eVar = (e) dVar;
            int i11 = eVar.f18032t;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                eVar.f18032t = i11 - Integer.MIN_VALUE;
                Object obj = eVar.f18030r;
                f10 = wm.d.f();
                i10 = eVar.f18032t;
                if (i10 != 0) {
                    y.b(obj);
                    IMyMailApi iMyMailApi = this.f17985a;
                    String E = E();
                    eVar.f18028p = this;
                    eVar.f18029q = myMailSubscribeBody;
                    eVar.f18032t = 1;
                    obj = iMyMailApi.subscribeToMyMail(E, myMailSubscribeBody, eVar);
                    if (obj == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    myMailSubscribeBody = (MyMailSubscribeBody) eVar.f18029q;
                    this = (b) eVar.f18028p;
                    y.b(obj);
                }
                resultWrapper = (ResultWrapper) obj;
                if (!(resultWrapper instanceof ResultWrapper.Error)) {
                    if (!(resultWrapper instanceof ResultWrapper.Success)) {
                        throw new rm.t();
                    }
                    this.j();
                    this.z(myMailSubscribeBody.getStatus());
                }
                return resultWrapper;
            }
        }
        eVar = new e(dVar);
        Object obj2 = eVar.f18030r;
        f10 = wm.d.f();
        i10 = eVar.f18032t;
        if (i10 != 0) {
        }
        resultWrapper = (ResultWrapper) obj2;
        if (!(resultWrapper instanceof ResultWrapper.Error)) {
        }
        return resultWrapper;
    }

    @Override // fa.a
    public a0 h() {
        return this.f18007w;
    }

    @Override // fa.a
    public MyMailStatus i() {
        return this.f17999o;
    }

    @Override // fa.a
    public Object isCaslOpted(CaslOptedBody caslOptedBody, vm.d dVar) {
        return this.f17985a.isCaslOpted(caslOptedBody, dVar);
    }

    @Override // fa.a
    public void j() {
        this.f17995k = null;
        this.f17996l = null;
        this.f17994j = 0L;
    }

    @Override // fa.a
    public a0 k() {
        return this.f18005u;
    }

    /* JADX WARN: Removed duplicated region for block: B:41:0x0049  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0025  */
    @Override // fa.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object l(vm.d dVar) {
        C0394b c0394b;
        Object f10;
        int i10;
        ResultWrapper resultWrapper;
        b bVar;
        ResultWrapper resultWrapper2;
        if (dVar instanceof C0394b) {
            c0394b = (C0394b) dVar;
            int i11 = c0394b.f18019t;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                c0394b.f18019t = i11 - Integer.MIN_VALUE;
                Object obj = c0394b.f18017r;
                f10 = wm.d.f();
                i10 = c0394b.f18019t;
                if (i10 != 0) {
                    y.b(obj);
                    if (H()) {
                        ResultWrapper resultWrapper3 = this.f17995k;
                        t.e(resultWrapper3, "null cannot be cast to non-null type ca.canadapost.core.data.model.ResultWrapper<ca.canadapost.core.data.mymail.model.MyMailSubscriptionResponse>");
                        return resultWrapper3;
                    }
                    IMyMailApi iMyMailApi = this.f17985a;
                    String E = E();
                    c0394b.f18015p = this;
                    c0394b.f18019t = 1;
                    obj = iMyMailApi.getMyMailSubscriptionInfo(E, c0394b);
                    if (obj == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        if (i10 != 2 && i10 != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        resultWrapper2 = (ResultWrapper) c0394b.f18016q;
                        bVar = (b) c0394b.f18015p;
                        y.b(obj);
                        bVar.f17994j = System.currentTimeMillis();
                        bVar.f17995k = resultWrapper2;
                        return resultWrapper2;
                    }
                    this = (b) c0394b.f18015p;
                    y.b(obj);
                }
                resultWrapper = (ResultWrapper) obj;
                if (!(resultWrapper instanceof ResultWrapper.Error) || !(resultWrapper instanceof ResultWrapper.Success)) {
                    return resultWrapper;
                }
                this.f17996l = null;
                ResultWrapper.Success success = (ResultWrapper.Success) resultWrapper;
                this.z(((MyMailSubscriptionResponse) success.getData()).getStatus());
                Preferences preferences = ((MyMailSubscriptionResponse) success.getData()).getPreferences();
                this.w(preferences != null ? t.b(preferences.getAcceptedTnC(), kotlin.coroutines.jvm.internal.b.a(true)) : false);
                if (((MyMailSubscriptionResponse) success.getData()).getStatus() == MyMailStatus.SUBSCRIBED) {
                    Preferences preferences2 = ((MyMailSubscriptionResponse) success.getData()).getPreferences();
                    if (preferences2 != null ? t.b(preferences2.getAcceptedTnC(), kotlin.coroutines.jvm.internal.b.a(true)) : false) {
                        c0394b.f18015p = this;
                        c0394b.f18016q = resultWrapper;
                        c0394b.f18019t = 2;
                        if (this.e(c0394b) == f10) {
                            return f10;
                        }
                        bVar = this;
                        resultWrapper2 = resultWrapper;
                        bVar.f17994j = System.currentTimeMillis();
                        bVar.f17995k = resultWrapper2;
                        return resultWrapper2;
                    }
                }
                c0394b.f18015p = this;
                c0394b.f18016q = resultWrapper;
                c0394b.f18019t = 3;
                if (this.C(c0394b) == f10) {
                    return f10;
                }
                bVar = this;
                resultWrapper2 = resultWrapper;
                bVar.f17994j = System.currentTimeMillis();
                bVar.f17995k = resultWrapper2;
                return resultWrapper2;
            }
        }
        c0394b = new C0394b(dVar);
        Object obj2 = c0394b.f18017r;
        f10 = wm.d.f();
        i10 = c0394b.f18019t;
        if (i10 != 0) {
        }
        resultWrapper = (ResultWrapper) obj2;
        if (!(resultWrapper instanceof ResultWrapper.Error)) {
        }
        return resultWrapper;
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0057  */
    /* JADX WARN: Removed duplicated region for block: B:21:0x003a  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0023  */
    @Override // fa.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object m(MyMailSubscribeBody myMailSubscribeBody, vm.d dVar) {
        f fVar;
        Object f10;
        int i10;
        ResultWrapper resultWrapper;
        if (dVar instanceof f) {
            fVar = (f) dVar;
            int i11 = fVar.f18037t;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                fVar.f18037t = i11 - Integer.MIN_VALUE;
                Object obj = fVar.f18035r;
                f10 = wm.d.f();
                i10 = fVar.f18037t;
                if (i10 != 0) {
                    y.b(obj);
                    IMyMailApi iMyMailApi = this.f17985a;
                    String E = E();
                    fVar.f18033p = this;
                    fVar.f18034q = myMailSubscribeBody;
                    fVar.f18037t = 1;
                    obj = iMyMailApi.updateSubscriptionsToMyMail(E, myMailSubscribeBody, fVar);
                    if (obj == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    myMailSubscribeBody = (MyMailSubscribeBody) fVar.f18034q;
                    this = (b) fVar.f18033p;
                    y.b(obj);
                }
                resultWrapper = (ResultWrapper) obj;
                if (!(resultWrapper instanceof ResultWrapper.Error)) {
                    if (!(resultWrapper instanceof ResultWrapper.Success)) {
                        throw new rm.t();
                    }
                    this.j();
                    this.z(myMailSubscribeBody.getStatus());
                }
                return resultWrapper;
            }
        }
        fVar = new f(dVar);
        Object obj2 = fVar.f18035r;
        f10 = wm.d.f();
        i10 = fVar.f18037t;
        if (i10 != 0) {
        }
        resultWrapper = (ResultWrapper) obj2;
        if (!(resultWrapper instanceof ResultWrapper.Error)) {
        }
        return resultWrapper;
    }

    @Override // fa.a
    public void n(Boolean bool) {
        MyMailFlowArguments myMailFlowArguments = (MyMailFlowArguments) this.f18000p.f();
        if (myMailFlowArguments == null) {
            return;
        }
        myMailFlowArguments.setHasAddressSupport(bool);
    }

    @Override // fa.a
    public void o(boolean z10) {
        this.f18008x.q(Boolean.valueOf(z10));
    }

    @Override // fa.a
    public a0 p() {
        return this.f18001q;
    }

    @Override // fa.a
    public void q(boolean z10) {
        this.f18002r.q(Boolean.valueOf(z10));
    }

    @Override // fa.a
    public a0 r() {
        return this.f18009y;
    }

    @Override // fa.a
    public a0 s() {
        return this.f18003s;
    }

    @Override // fa.a
    public Object t(vm.d dVar) {
        return this.f17985a.removeSubscriptionToMyMail(E(), dVar);
    }

    @Override // fa.a
    public boolean u() {
        if (i() != MyMailStatus.SUBSCRIBED) {
            return false;
        }
        MyMailFlowArguments myMailFlowArguments = (MyMailFlowArguments) p().f();
        return myMailFlowArguments != null && myMailFlowArguments.getIsTncAccepted();
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0061  */
    /* JADX WARN: Removed duplicated region for block: B:22:0x0035  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0023  */
    @Override // fa.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object v(AddressEligibilityBody addressEligibilityBody, boolean z10, vm.d dVar) {
        g gVar;
        Object f10;
        int i10;
        ResultWrapper resultWrapper;
        if (dVar instanceof g) {
            gVar = (g) dVar;
            int i11 = gVar.f18041s;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                gVar.f18041s = i11 - Integer.MIN_VALUE;
                Object obj = gVar.f18039q;
                f10 = wm.d.f();
                i10 = gVar.f18041s;
                if (i10 != 0) {
                    y.b(obj);
                    if (this.f17996l != null && H() && !z10) {
                        ResultWrapper resultWrapper2 = this.f17996l;
                        t.e(resultWrapper2, "null cannot be cast to non-null type ca.canadapost.core.data.model.ResultWrapper<ca.canadapost.core.data.mymail.model.AddressEligibilityResponse>");
                        return resultWrapper2;
                    }
                    IMyMailApi iMyMailApi = this.f17985a;
                    gVar.f18038p = this;
                    gVar.f18041s = 1;
                    obj = iMyMailApi.verifyAddressEligibility(addressEligibilityBody, gVar);
                    if (obj == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    this = (b) gVar.f18038p;
                    y.b(obj);
                }
                resultWrapper = (ResultWrapper) obj;
                if (!(resultWrapper instanceof ResultWrapper.Error)) {
                    if (!(resultWrapper instanceof ResultWrapper.Success)) {
                        throw new rm.t();
                    }
                    this.n(kotlin.coroutines.jvm.internal.b.a(((AddressEligibilityResponse) ((ResultWrapper.Success) resultWrapper).getData()).isAddressSupported()));
                    this.f17996l = resultWrapper;
                }
                return resultWrapper;
            }
        }
        gVar = new g(dVar);
        Object obj2 = gVar.f18039q;
        f10 = wm.d.f();
        i10 = gVar.f18041s;
        if (i10 != 0) {
        }
        resultWrapper = (ResultWrapper) obj2;
        if (!(resultWrapper instanceof ResultWrapper.Error)) {
        }
        return resultWrapper;
    }

    @Override // fa.a
    public void w(boolean z10) {
        MyMailFlowArguments myMailFlowArguments = (MyMailFlowArguments) this.f18000p.f();
        if (myMailFlowArguments == null) {
            return;
        }
        myMailFlowArguments.setTncAccepted(z10);
    }

    @Override // fa.a
    public void x(boolean z10) {
        this.f18006v.q(Boolean.valueOf(z10));
    }

    @Override // fa.a
    public String y(ImageDimensions imageDimensions) {
        t.g(imageDimensions, "imageDimensions");
        return MailPieceKt.getImageDimensionsToSize().get(imageDimensions);
    }

    @Override // fa.a
    public void z(MyMailStatus myMailStatus) {
        this.f17999o = myMailStatus;
    }
}
