package dc;

import android.app.Application;
import android.content.Context;
import ca.canadapost.core.data.findrate.model.FindRateDataModel;
import ca.canadapost.core.data.findrate.model.FindRateResponse;
import ca.canadapost.core.data.findrate.model.FindRateResponseItem;
import ca.canadapost.core.data.findrate.model.KahalaServiceDateResponse;
import ca.canadapost.core.data.findrate.model.Product;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import d9.f;
import java.util.List;
import java.util.Map;
import l8.h;
import org.joda.time.DateTime;
import org.joda.time.Days;
import tp.u1;

/* loaded from: classes4.dex */
public final class u0 extends androidx.lifecycle.b implements l8.h, l8.c, o8.h0 {

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

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

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

    /* renamed from: f, reason: collision with root package name */
    private final FindRateDataModel f16186f;

    /* renamed from: g, reason: collision with root package name */
    private final p9.h f16187g;

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

    /* renamed from: i, reason: collision with root package name */
    private final /* synthetic */ l8.i f16189i;

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

    /* renamed from: k, reason: collision with root package name */
    private final /* synthetic */ o8.i0 f16191k;

    /* renamed from: l, reason: collision with root package name */
    private final l8.e f16192l;

    /* renamed from: m, reason: collision with root package name */
    private final androidx.lifecycle.f0 f16193m;

    /* renamed from: n, reason: collision with root package name */
    private final androidx.lifecycle.a0 f16194n;

    /* renamed from: o, reason: collision with root package name */
    private final androidx.lifecycle.f0 f16195o;

    /* renamed from: p, reason: collision with root package name */
    private final androidx.lifecycle.a0 f16196p;

    /* renamed from: q, reason: collision with root package name */
    private final androidx.lifecycle.f0 f16197q;

    /* renamed from: r, reason: collision with root package name */
    private final androidx.lifecycle.a0 f16198r;

    /* renamed from: s, reason: collision with root package name */
    private final androidx.lifecycle.f0 f16199s;

    /* renamed from: t, reason: collision with root package name */
    private final androidx.lifecycle.a0 f16200t;

    /* renamed from: v, reason: collision with root package name */
    static final /* synthetic */ kn.l[] f16182v = {kotlin.jvm.internal.p0.h(new kotlin.jvm.internal.g0(u0.class, "doubleClickGuard", "getDoubleClickGuard()Z", 0))};

    /* renamed from: u, reason: collision with root package name */
    public static final a f16181u = new a(null);

    /* loaded from: classes4.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(kotlin.jvm.internal.k kVar) {
            this();
        }
    }

    /* 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 f16201p;

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            KahalaServiceDateResponse.GuaranteeDateResponseObject guaranteeDateResponse;
            KahalaServiceDateResponse.GuaranteeDateInfoObject guaranteeDateInfo;
            String svcGuaranteeTms;
            f10 = wm.d.f();
            int i10 = this.f16201p;
            if (i10 == 0) {
                rm.y.b(obj);
                s9.c cVar = u0.this.f16183c;
                FindRateDataModel findRateDataModel = this.f16203r;
                this.f16201p = 1;
                obj = cVar.e(findRateDataModel, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                rm.y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Success) {
                f.a.a(u0.this.f16184d, "FAR_Search_Adobe", null, 2, null);
                ResultWrapper.Success success = (ResultWrapper.Success) resultWrapper;
                if (((FindRateResponse) ((rm.v) success.getData()).c()).getDelRateStd() == null && u0.this.i0()) {
                    u0 u0Var = u0.this;
                    u0Var.e0(new ResultWrapper.Error(null, u0Var.f16185e.getString(h0.f16065a0), RepositoryError.ServiceError, null, 8, null), true);
                } else {
                    u0.this.f16193m.q(((FindRateResponse) ((rm.v) success.getData()).c()).getDelRateStd());
                    KahalaServiceDateResponse kahalaServiceDateResponse = (KahalaServiceDateResponse) ((rm.v) success.getData()).d();
                    if (kahalaServiceDateResponse != null && (guaranteeDateResponse = kahalaServiceDateResponse.getGuaranteeDateResponse()) != null && (guaranteeDateInfo = guaranteeDateResponse.getGuaranteeDateInfo()) != null && (svcGuaranteeTms = guaranteeDateInfo.getSvcGuaranteeTms()) != null) {
                        u0 u0Var2 = u0.this;
                        DateTime t10 = qa.d.t(svcGuaranteeTms);
                        u0Var2.f16197q.q(t10);
                        u0Var2.f16195o.q(kotlin.coroutines.jvm.internal.b.c(Days.t(new DateTime(), t10).u()));
                    }
                }
            } else if ((resultWrapper instanceof ResultWrapper.Error) && u0.this.i0()) {
                ResultWrapper.Error error = (ResultWrapper.Error) resultWrapper;
                u0.this.e0(new ResultWrapper.Error(error.getException(), u0.this.f16185e.getString(h0.f16065a0), error.getError(), null, 8, null), true);
            }
            return rm.n0.f34904a;
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public u0(s9.c repository, d9.f analyticsService, t7.c contextService, FindRateDataModel findRateDataModel, p9.h featureFlagRepository, g9.d sessionRepository) {
        super((Application) r0);
        kotlin.jvm.internal.t.g(repository, "repository");
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(featureFlagRepository, "featureFlagRepository");
        kotlin.jvm.internal.t.g(sessionRepository, "sessionRepository");
        Context a10 = contextService.a();
        kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f16183c = repository;
        this.f16184d = analyticsService;
        this.f16185e = contextService;
        this.f16186f = findRateDataModel;
        this.f16187g = featureFlagRepository;
        this.f16188h = sessionRepository;
        this.f16189i = new l8.i(contextService);
        this.f16190j = new l8.d();
        this.f16191k = new o8.i0(analyticsService, sessionRepository);
        this.f16192l = new l8.e(false, 0L, 3, null);
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0();
        this.f16193m = f0Var;
        this.f16194n = f0Var;
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0();
        this.f16195o = f0Var2;
        this.f16196p = f0Var2;
        androidx.lifecycle.f0 f0Var3 = new androidx.lifecycle.f0();
        this.f16197q = f0Var3;
        this.f16198r = f0Var3;
        androidx.lifecycle.f0 f0Var4 = new androidx.lifecycle.f0();
        this.f16199s = f0Var4;
        this.f16200t = f0Var4;
        f0Var4.q(findRateDataModel != null ? findRateDataModel.kahalaProducts : null);
    }

    private final boolean g0(FindRateResponseItem findRateResponseItem) {
        Boolean carbonNeutral;
        Product product = findRateResponseItem.getProduct();
        if (product == null || (carbonNeutral = product.getCarbonNeutral()) == null) {
            return false;
        }
        return carbonNeutral.booleanValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean i0() {
        FindRateDataModel findRateDataModel = this.f16186f;
        kotlin.jvm.internal.t.d(findRateDataModel);
        return kotlin.jvm.internal.t.b("PERSONAL", findRateDataModel.segment);
    }

    private final boolean j0(FindRateResponseItem findRateResponseItem) {
        Boolean mostFuelEfficient;
        Product product = findRateResponseItem.getProduct();
        if (product == null || (mostFuelEfficient = product.getMostFuelEfficient()) == null) {
            return false;
        }
        return mostFuelEfficient.booleanValue();
    }

    @Override // l8.h
    public androidx.lifecycle.a0 J() {
        return this.f16189i.J();
    }

    public final void X(FindRateResponseItem item) {
        Map p10;
        List<String> names;
        kotlin.jvm.internal.t.g(item, "item");
        boolean j02 = j0(item);
        boolean g02 = g0(item);
        String str = (j02 && g02) ? "Rate List - Most Fuel Efficient and Carbon Neutral" : j02 ? "Rate List - Most Fuel Efficient" : g02 ? "Rate List - Carbon Neutral" : "Rate List - Regular";
        Product product = item.getProduct();
        String str2 = str + " | " + ((product == null || (names = product.getNames()) == null) ? null : names.get(0));
        d9.f fVar = this.f16184d;
        p10 = sm.q0.p(d9.e.f15943f.a("FAR_RESULTS_VIEW"), rm.c0.a("e.Var13", str2));
        fVar.b("Rate_list_item_click_Adobe", p10);
    }

    public final void Y() {
        FindRateDataModel findRateDataModel = this.f16186f;
        if (findRateDataModel == null) {
            return;
        }
        h.a.a(this, androidx.lifecycle.a1.a(this), null, null, null, new b(findRateDataModel, null), 7, null);
    }

    public final FindRateDataModel Z() {
        return this.f16186f;
    }

    public final androidx.lifecycle.a0 a0() {
        return this.f16200t;
    }

    public final androidx.lifecycle.a0 b0() {
        return this.f16194n;
    }

    public final androidx.lifecycle.a0 c0() {
        return this.f16198r;
    }

    public final androidx.lifecycle.a0 d0() {
        return this.f16196p;
    }

    public void e0(ResultWrapper.Error error, boolean z10) {
        kotlin.jvm.internal.t.g(error, "error");
        this.f16190j.a(error, z10);
    }

    public final boolean f0() {
        if (((List) this.f16193m.f()) != null) {
            return !r0.isEmpty();
        }
        return false;
    }

    public final boolean h0() {
        return this.f16187g.d(p9.a.CARBON_CALCULATOR_REVAMP);
    }

    public final void k0() {
    }

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

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

    @Override // l8.h
    public u1 u(tp.m0 m0Var, vm.g context, tp.o0 start, String str, dn.p block) {
        kotlin.jvm.internal.t.g(m0Var, "<this>");
        kotlin.jvm.internal.t.g(context, "context");
        kotlin.jvm.internal.t.g(start, "start");
        kotlin.jvm.internal.t.g(block, "block");
        return this.f16189i.u(m0Var, context, start, str, block);
    }

    @Override // o8.h0
    public androidx.lifecycle.a0 v() {
        return this.f16191k.v();
    }
}
