package ub;

import androidx.lifecycle.a0;
import androidx.lifecycle.z0;
import ca.canadapost.core.data.auth.model.UserProfile;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.module.epostprofile.account.changepassword.model.ChangePasswordErrorMessage;
import ca.canadapost.module.epostprofile.account.changepassword.model.ChangePasswordResponse;
import dn.p;
import g9.l;
import java.util.List;
import kotlin.jvm.internal.t;
import rm.n0;
import rm.y;
import sm.c0;
import tp.a1;
import tp.g2;
import tp.i;
import tp.i0;
import tp.k;
import tp.m0;
import wp.s;
import wp.x;
import wp.z;

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

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

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

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

    /* renamed from: e, reason: collision with root package name */
    private final i0 f37106e;

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

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

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

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

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

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

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

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

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

        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.f37114p;
            if (i10 == 0) {
                y.b(obj);
                s sVar = c.this.f37112k;
                this.f37114p = 1;
                if (sVar.emit("", this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            return n0.f34904a;
        }

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

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

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

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

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

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ String f37120t;

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

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

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

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

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            a(ResultWrapper resultWrapper, c cVar, vm.d dVar) {
                super(2, dVar);
                this.f37122q = resultWrapper;
                this.f37123r = cVar;
            }

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

            /* JADX WARN: Code restructure failed: missing block: B:17:0x00b8, code lost:
            
                if (r1 != null) goto L43;
             */
            /* JADX WARN: Removed duplicated region for block: B:14:0x00ac  */
            /* JADX WARN: Removed duplicated region for block: B:20:0x00c4 A[RETURN] */
            /* JADX WARN: Removed duplicated region for block: B:28:0x0082 A[RETURN] */
            /* JADX WARN: Removed duplicated region for block: B:32:0x006f A[RETURN] */
            @Override // kotlin.coroutines.jvm.internal.a
            /*
                Code decompiled incorrectly, please refer to instructions dump.
            */
            public final Object invokeSuspend(Object obj) {
                Object f10;
                s sVar;
                Boolean a10;
                s sVar2;
                Boolean a11;
                s sVar3;
                List<ChangePasswordErrorMessage> errorMessageList;
                String str;
                Object c02;
                f10 = wm.d.f();
                int i10 = this.f37121p;
                if (i10 == 0) {
                    y.b(obj);
                    String response = ((ChangePasswordResponse) ((ResultWrapper.Success) this.f37122q).getData()).getResponse();
                    if (response == null || response.length() == 0) {
                        s sVar4 = this.f37123r.f37108g;
                        Boolean a12 = kotlin.coroutines.jvm.internal.b.a(false);
                        this.f37121p = 4;
                        if (sVar4.emit(a12, this) == f10) {
                            return f10;
                        }
                        sVar3 = this.f37123r.f37112k;
                        errorMessageList = ((ChangePasswordResponse) ((ResultWrapper.Success) this.f37122q).getData()).getErrorMessageList();
                        if (errorMessageList != null) {
                        }
                        str = "";
                        this.f37121p = 5;
                        if (sVar3.emit(str, this) == f10) {
                        }
                    } else {
                        c cVar = this.f37123r;
                        this.f37121p = 1;
                        if (cVar.Z(this) == f10) {
                            return f10;
                        }
                        sVar = this.f37123r.f37108g;
                        a10 = kotlin.coroutines.jvm.internal.b.a(false);
                        this.f37121p = 2;
                        if (sVar.emit(a10, this) == f10) {
                        }
                        sVar2 = this.f37123r.f37110i;
                        a11 = kotlin.coroutines.jvm.internal.b.a(true);
                        this.f37121p = 3;
                        if (sVar2.emit(a11, this) == f10) {
                        }
                    }
                } else if (i10 == 1) {
                    y.b(obj);
                    sVar = this.f37123r.f37108g;
                    a10 = kotlin.coroutines.jvm.internal.b.a(false);
                    this.f37121p = 2;
                    if (sVar.emit(a10, this) == f10) {
                        return f10;
                    }
                    sVar2 = this.f37123r.f37110i;
                    a11 = kotlin.coroutines.jvm.internal.b.a(true);
                    this.f37121p = 3;
                    if (sVar2.emit(a11, this) == f10) {
                    }
                } else if (i10 != 2) {
                    if (i10 != 3) {
                        if (i10 == 4) {
                            y.b(obj);
                            sVar3 = this.f37123r.f37112k;
                            errorMessageList = ((ChangePasswordResponse) ((ResultWrapper.Success) this.f37122q).getData()).getErrorMessageList();
                            if (errorMessageList != null) {
                                c02 = c0.c0(errorMessageList);
                                ChangePasswordErrorMessage changePasswordErrorMessage = (ChangePasswordErrorMessage) c02;
                                if (changePasswordErrorMessage != null) {
                                    str = changePasswordErrorMessage.getMessage();
                                }
                            }
                            str = "";
                            this.f37121p = 5;
                            if (sVar3.emit(str, this) == f10) {
                                return f10;
                            }
                        } else if (i10 != 5) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                    }
                    y.b(obj);
                } else {
                    y.b(obj);
                    sVar2 = this.f37123r.f37110i;
                    a11 = kotlin.coroutines.jvm.internal.b.a(true);
                    this.f37121p = 3;
                    if (sVar2.emit(a11, this) == f10) {
                        return f10;
                    }
                }
                return n0.f34904a;
            }

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

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: ub.c$b$b, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        public static final class C0887b extends kotlin.coroutines.jvm.internal.l implements p {

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

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

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

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            C0887b(c cVar, ResultWrapper resultWrapper, vm.d dVar) {
                super(2, dVar);
                this.f37125q = cVar;
                this.f37126r = resultWrapper;
            }

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

            @Override // kotlin.coroutines.jvm.internal.a
            public final Object invokeSuspend(Object obj) {
                wm.d.f();
                if (this.f37124p != 0) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
                this.f37125q.Y((ResultWrapper.Error) this.f37126r, true);
                return n0.f34904a;
            }

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(String str, String str2, vm.d dVar) {
            super(2, dVar);
            this.f37119s = str;
            this.f37120t = str2;
        }

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

        /* JADX WARN: Failed to find 'out' block for switch in B:2:0x0008. Please report as an issue. */
        /* JADX WARN: Removed duplicated region for block: B:15:0x00c4 A[RETURN] */
        /* JADX WARN: Removed duplicated region for block: B:20:0x007f  */
        /* JADX WARN: Removed duplicated region for block: B:23:0x0094  */
        /* JADX WARN: Removed duplicated region for block: B:32:0x0061  */
        /* JADX WARN: Removed duplicated region for block: B:34:0x0069  */
        /* JADX WARN: Removed duplicated region for block: B:37:0x0078 A[RETURN] */
        /* JADX WARN: Removed duplicated region for block: B:38:0x0066  */
        /* JADX WARN: Removed duplicated region for block: B:9:0x00db A[RETURN] */
        @Override // kotlin.coroutines.jvm.internal.a
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            Object f10;
            String userName;
            ResultWrapper resultWrapper;
            ResultWrapper resultWrapper2;
            s sVar;
            Boolean a10;
            g2 c10;
            C0887b c0887b;
            f10 = wm.d.f();
            switch (this.f37117q) {
                case 0:
                    y.b(obj);
                    s sVar2 = c.this.f37108g;
                    Boolean a11 = kotlin.coroutines.jvm.internal.b.a(true);
                    this.f37117q = 1;
                    if (sVar2.emit(a11, this) == f10) {
                        return f10;
                    }
                    tb.c cVar = c.this.f37104c;
                    UserProfile userProfile = (UserProfile) c.this.f37103b.a().f();
                    userName = userProfile == null ? userProfile.getUserName() : null;
                    if (userName == null) {
                        userName = "";
                    }
                    String str = this.f37119s;
                    String str2 = this.f37120t;
                    this.f37117q = 2;
                    obj = cVar.b(userName, str, str2, this);
                    if (obj == f10) {
                        return f10;
                    }
                    resultWrapper = (ResultWrapper) obj;
                    if (resultWrapper instanceof ResultWrapper.Success) {
                        g2 c11 = a1.c();
                        a aVar = new a(resultWrapper, c.this, null);
                        this.f37117q = 3;
                        if (i.g(c11, aVar, this) == f10) {
                            return f10;
                        }
                    } else if (resultWrapper instanceof ResultWrapper.Error) {
                        s sVar3 = c.this.f37110i;
                        Boolean a12 = kotlin.coroutines.jvm.internal.b.a(false);
                        this.f37116p = resultWrapper;
                        this.f37117q = 4;
                        if (sVar3.emit(a12, this) == f10) {
                            return f10;
                        }
                        resultWrapper2 = resultWrapper;
                        sVar = c.this.f37108g;
                        a10 = kotlin.coroutines.jvm.internal.b.a(false);
                        this.f37116p = resultWrapper2;
                        this.f37117q = 5;
                        if (sVar.emit(a10, this) == f10) {
                            return f10;
                        }
                        c10 = a1.c();
                        c0887b = new C0887b(c.this, resultWrapper2, null);
                        this.f37116p = null;
                        this.f37117q = 6;
                        if (i.g(c10, c0887b, this) == f10) {
                            return f10;
                        }
                    }
                    return n0.f34904a;
                case 1:
                    y.b(obj);
                    tb.c cVar2 = c.this.f37104c;
                    UserProfile userProfile2 = (UserProfile) c.this.f37103b.a().f();
                    if (userProfile2 == null) {
                    }
                    if (userName == null) {
                    }
                    String str3 = this.f37119s;
                    String str22 = this.f37120t;
                    this.f37117q = 2;
                    obj = cVar2.b(userName, str3, str22, this);
                    if (obj == f10) {
                    }
                    resultWrapper = (ResultWrapper) obj;
                    if (resultWrapper instanceof ResultWrapper.Success) {
                    }
                    return n0.f34904a;
                case 2:
                    y.b(obj);
                    resultWrapper = (ResultWrapper) obj;
                    if (resultWrapper instanceof ResultWrapper.Success) {
                    }
                    return n0.f34904a;
                case 3:
                case 6:
                    y.b(obj);
                    return n0.f34904a;
                case 4:
                    resultWrapper2 = (ResultWrapper) this.f37116p;
                    y.b(obj);
                    sVar = c.this.f37108g;
                    a10 = kotlin.coroutines.jvm.internal.b.a(false);
                    this.f37116p = resultWrapper2;
                    this.f37117q = 5;
                    if (sVar.emit(a10, this) == f10) {
                    }
                    c10 = a1.c();
                    c0887b = new C0887b(c.this, resultWrapper2, null);
                    this.f37116p = null;
                    this.f37117q = 6;
                    if (i.g(c10, c0887b, this) == f10) {
                    }
                    return n0.f34904a;
                case 5:
                    resultWrapper2 = (ResultWrapper) this.f37116p;
                    y.b(obj);
                    c10 = a1.c();
                    c0887b = new C0887b(c.this, resultWrapper2, null);
                    this.f37116p = null;
                    this.f37117q = 6;
                    if (i.g(c10, c0887b, this) == f10) {
                    }
                    return n0.f34904a;
                default:
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
        }

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

    public c(ka.b profileRepository, tb.c changePasswordRepository, l userAuthenticationRepository, i0 dispatcher) {
        t.g(profileRepository, "profileRepository");
        t.g(changePasswordRepository, "changePasswordRepository");
        t.g(userAuthenticationRepository, "userAuthenticationRepository");
        t.g(dispatcher, "dispatcher");
        this.f37103b = profileRepository;
        this.f37104c = changePasswordRepository;
        this.f37105d = userAuthenticationRepository;
        this.f37106e = dispatcher;
        this.f37107f = new l8.d();
        s b10 = z.b(0, 0, null, 7, null);
        this.f37108g = b10;
        this.f37109h = wp.g.a(b10);
        s b11 = z.b(0, 0, null, 7, null);
        this.f37110i = b11;
        this.f37111j = wp.g.a(b11);
        s b12 = z.b(0, 0, null, 7, null);
        this.f37112k = b12;
        this.f37113l = wp.g.a(b12);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Object Z(vm.d dVar) {
        Object f10;
        Object e10 = this.f37105d.e(dVar);
        f10 = wm.d.f();
        return e10 == f10 ? e10 : n0.f34904a;
    }

    public final x V() {
        return this.f37113l;
    }

    public final x W() {
        return this.f37111j;
    }

    public final x X() {
        return this.f37109h;
    }

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

    public final void a0() {
        k.d(androidx.lifecycle.a1.a(this), null, null, new a(null), 3, null);
    }

    public final void b0(String oldPassword, String newPassword) {
        t.g(oldPassword, "oldPassword");
        t.g(newPassword, "newPassword");
        k.d(androidx.lifecycle.a1.a(this), this.f37106e, null, new b(oldPassword, newPassword, null), 2, null);
    }

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

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