package lg;

import ca.canadapost.core.data.google.api.IGooglePassApi;
import ca.canadapost.core.data.google.model.googlepass.GooglePass;
import ca.canadapost.core.data.google.model.googlepass.GooglePassType;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.module.track.model.DeliveryPickupPass;
import ca.canadapost.module.track.model.ReceiptPass;
import dn.p;
import kotlin.coroutines.jvm.internal.l;
import kotlin.jvm.internal.t;
import rm.n0;
import rm.y;
import tp.a1;
import tp.m0;
import tp.n1;
import uq.e0;

/* loaded from: classes4.dex */
public final class b implements lg.a {

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

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

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

        /* renamed from: r, reason: collision with root package name */
        int f28084r;

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

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

    /* renamed from: lg.b$b, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    static final class C0627b extends l implements p {

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

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

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ dn.l f28088s;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        C0627b(DeliveryPickupPass deliveryPickupPass, dn.l lVar, vm.d dVar) {
            super(2, dVar);
            this.f28087r = deliveryPickupPass;
            this.f28088s = lVar;
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f28085p;
            if (i10 == 0) {
                y.b(obj);
                b bVar = b.this;
                DeliveryPickupPass deliveryPickupPass = this.f28087r;
                this.f28085p = 1;
                obj = bVar.c(deliveryPickupPass, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            this.f28088s.invoke((ResultWrapper) obj);
            return n0.f34904a;
        }

        @Override // dn.p
        public final Object invoke(m0 m0Var, vm.d dVar) {
            return ((C0627b) 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 */
        /* synthetic */ Object f28089p;

        /* renamed from: r, reason: collision with root package name */
        int f28091r;

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

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

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

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

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

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ dn.l f28095s;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        d(ReceiptPass receiptPass, dn.l lVar, vm.d dVar) {
            super(2, dVar);
            this.f28094r = receiptPass;
            this.f28095s = lVar;
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f28092p;
            if (i10 == 0) {
                y.b(obj);
                b bVar = b.this;
                ReceiptPass receiptPass = this.f28094r;
                this.f28092p = 1;
                obj = bVar.d(receiptPass, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            this.f28095s.invoke((ResultWrapper) obj);
            return n0.f34904a;
        }

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

    public b(IGooglePassApi googlePassApi) {
        t.g(googlePassApi, "googlePassApi");
        this.f28081a = googlePassApi;
    }

    @Override // lg.a
    public void a(ReceiptPass pass, dn.l callback) {
        t.g(pass, "pass");
        t.g(callback, "callback");
        yp.b.b(n1.f36567p, a1.c(), null, new d(pass, callback, null), 2, null);
    }

    @Override // lg.a
    public void b(DeliveryPickupPass pass, dn.l callback) {
        t.g(pass, "pass");
        t.g(callback, "callback");
        yp.b.b(n1.f36567p, a1.c(), null, new C0627b(pass, callback, null), 2, null);
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0034  */
    /* JADX WARN: Removed duplicated region for block: B:9:0x0023  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object c(DeliveryPickupPass deliveryPickupPass, vm.d dVar) {
        a aVar;
        Object f10;
        int i10;
        try {
            if (dVar instanceof a) {
                aVar = (a) dVar;
                int i11 = aVar.f28084r;
                if ((i11 & Integer.MIN_VALUE) != 0) {
                    aVar.f28084r = i11 - Integer.MIN_VALUE;
                    Object obj = aVar.f28082p;
                    f10 = wm.d.f();
                    i10 = aVar.f28084r;
                    if (i10 != 0) {
                        y.b(obj);
                        IGooglePassApi iGooglePassApi = this.f28081a;
                        String urlPath = GooglePassType.DeliveryPickupPass.getUrlPath();
                        GooglePass googlePass = deliveryPickupPass.toGooglePass();
                        aVar.f28084r = 1;
                        obj = iGooglePassApi.createGooglePass(urlPath, googlePass, aVar);
                        if (obj == f10) {
                            return f10;
                        }
                    } else {
                        if (i10 != 1) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        y.b(obj);
                    }
                    return new ResultWrapper.Success(((e0) obj).j());
                }
            }
            if (i10 != 0) {
            }
            return new ResultWrapper.Success(((e0) obj).j());
        } catch (Exception e10) {
            tr.a.f36618a.d(e10, e10.getMessage(), new Object[0]);
            return new ResultWrapper.Error(e10, "Error while getting google pass token", RepositoryError.ClientError, null, 8, null);
        }
        aVar = new a(dVar);
        Object obj2 = aVar.f28082p;
        f10 = wm.d.f();
        i10 = aVar.f28084r;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0035  */
    /* JADX WARN: Removed duplicated region for block: B:9:0x0024  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object d(ReceiptPass receiptPass, vm.d dVar) {
        c cVar;
        Object f10;
        int i10;
        try {
            if (dVar instanceof c) {
                cVar = (c) dVar;
                int i11 = cVar.f28091r;
                if ((i11 & Integer.MIN_VALUE) != 0) {
                    cVar.f28091r = i11 - Integer.MIN_VALUE;
                    Object obj = cVar.f28089p;
                    f10 = wm.d.f();
                    i10 = cVar.f28091r;
                    if (i10 != 0) {
                        y.b(obj);
                        tr.a.f36618a.e("TrackGooglePass", new com.google.gson.d().v(receiptPass.toGooglePass(), GooglePass.class));
                        IGooglePassApi iGooglePassApi = this.f28081a;
                        String urlPath = GooglePassType.DutyAndTaxesPass.getUrlPath();
                        GooglePass googlePass = receiptPass.toGooglePass();
                        cVar.f28091r = 1;
                        obj = iGooglePassApi.createGooglePass(urlPath, googlePass, cVar);
                        if (obj == f10) {
                            return f10;
                        }
                    } else {
                        if (i10 != 1) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        y.b(obj);
                    }
                    return new ResultWrapper.Success(((e0) obj).j());
                }
            }
            if (i10 != 0) {
            }
            return new ResultWrapper.Success(((e0) obj).j());
        } catch (Exception e10) {
            tr.a.f36618a.d(e10, e10.getMessage(), new Object[0]);
            return new ResultWrapper.Error(e10, "Error while getting google pass token", RepositoryError.ClientError, null, 8, null);
        }
        cVar = new c(dVar);
        Object obj2 = cVar.f28089p;
        f10 = wm.d.f();
        i10 = cVar.f28091r;
    }
}
