package ca.canadapost.module.addresscomplete;

import android.app.Application;
import androidx.lifecycle.a0;
import androidx.lifecycle.f0;
import androidx.lifecycle.g0;
import ca.canadapost.core.data.addresscomplete.webservice.AddressCompleteFindItem;
import ca.canadapost.core.data.model.Event;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.module.addresscomplete.b;
import dn.l;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import rm.n0;
import t7.c;
import w8.p;
import w8.q;

/* loaded from: classes4.dex */
public class b extends androidx.lifecycle.b {
    private final f0 A;
    public final a0 B;
    public final f0 C;
    private final f0 D;
    public final a0 E;
    g0 F;
    g0 G;
    protected a H;

    /* renamed from: c, reason: collision with root package name */
    public final f0 f8087c;

    /* renamed from: d, reason: collision with root package name */
    public final f0 f8088d;

    /* renamed from: e, reason: collision with root package name */
    public final f0 f8089e;

    /* renamed from: f, reason: collision with root package name */
    public final f0 f8090f;

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

    /* renamed from: h, reason: collision with root package name */
    public final a0 f8092h;

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

    /* renamed from: j, reason: collision with root package name */
    public final f0 f8094j;

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

    /* renamed from: l, reason: collision with root package name */
    public final a0 f8096l;

    /* renamed from: m, reason: collision with root package name */
    protected final c f8097m;

    /* renamed from: n, reason: collision with root package name */
    protected final o9.c f8098n;

    /* renamed from: o, reason: collision with root package name */
    protected final q f8099o;

    /* renamed from: p, reason: collision with root package name */
    protected final ca.a f8100p;

    /* renamed from: q, reason: collision with root package name */
    protected final n9.a f8101q;

    /* renamed from: r, reason: collision with root package name */
    protected final p f8102r;

    /* renamed from: s, reason: collision with root package name */
    protected final a9.b f8103s;

    /* renamed from: t, reason: collision with root package name */
    private Executor f8104t;

    /* renamed from: u, reason: collision with root package name */
    private String f8105u;

    /* renamed from: v, reason: collision with root package name */
    public String f8106v;

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

    /* renamed from: x, reason: collision with root package name */
    public final a0 f8108x;

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

    /* renamed from: z, reason: collision with root package name */
    public final a0 f8110z;

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes4.dex */
    public class a implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        protected final Object f8111p;

        /* renamed from: q, reason: collision with root package name */
        public long f8112q;

        /* renamed from: r, reason: collision with root package name */
        public String f8113r;

        /* renamed from: s, reason: collision with root package name */
        public String f8114s;

        /* JADX INFO: Access modifiers changed from: private */
        public /* synthetic */ n0 b(ResultWrapper resultWrapper) {
            b.this.f8090f.q(Boolean.FALSE);
            if (resultWrapper instanceof ResultWrapper.Success) {
                b.this.f8088d.q((List) ((ResultWrapper.Success) resultWrapper).getData());
            }
            return n0.f34904a;
        }

        @Override // java.lang.Runnable
        public void run() {
            synchronized (this.f8111p) {
                this.f8112q++;
                b.this.f8090f.q(Boolean.TRUE);
                b bVar = b.this;
                bVar.f8103s.f(this.f8113r, this.f8114s, bVar.f8105u, b.this.f8100p.c(), new l() { // from class: ca.canadapost.module.addresscomplete.a
                    @Override // dn.l
                    public final Object invoke(Object obj) {
                        n0 b10;
                        b10 = b.a.this.b((ResultWrapper) obj);
                        return b10;
                    }
                });
            }
        }

        private a() {
            this.f8111p = new Object();
            this.f8112q = 0L;
        }
    }

    public b(c cVar, q qVar, o9.c cVar2, ca.a aVar, n9.a aVar2, p pVar, a9.b bVar) {
        super((Application) cVar.a());
        f0 f0Var = new f0();
        this.f8087c = f0Var;
        f0 f0Var2 = new f0();
        this.f8088d = f0Var2;
        f0 f0Var3 = new f0();
        this.f8089e = f0Var3;
        f0 f0Var4 = new f0();
        this.f8090f = f0Var4;
        f0 f0Var5 = new f0();
        this.f8091g = f0Var5;
        this.f8092h = f0Var5;
        this.f8093i = new f0();
        f0 f0Var6 = new f0();
        this.f8094j = f0Var6;
        f0 f0Var7 = new f0();
        this.f8095k = f0Var7;
        this.f8096l = f0Var7;
        this.f8105u = "CA";
        this.f8106v = "";
        Boolean bool = Boolean.FALSE;
        f0 f0Var8 = new f0(bool);
        this.f8107w = f0Var8;
        this.f8108x = f0Var8;
        f0 f0Var9 = new f0(Boolean.TRUE);
        this.f8109y = f0Var9;
        this.f8110z = f0Var9;
        f0 f0Var10 = new f0();
        this.A = f0Var10;
        this.B = f0Var10;
        this.C = new f0(bool);
        f0 f0Var11 = new f0(bool);
        this.D = f0Var11;
        this.E = f0Var11;
        this.F = new g0() { // from class: za.w
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                ca.canadapost.module.addresscomplete.b.this.a0((String) obj);
            }
        };
        this.G = new g0() { // from class: za.x
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                ca.canadapost.module.addresscomplete.b.this.c0((AddressCompleteFindItem) obj);
            }
        };
        this.H = new a();
        this.f8097m = cVar;
        this.f8098n = cVar2;
        this.f8099o = qVar;
        this.f8100p = aVar;
        this.f8101q = aVar2;
        this.f8102r = pVar;
        this.f8103s = bVar;
        f0Var4.q(bool);
        f0Var7.q(bool);
        f0Var2.q(new ArrayList());
        f0Var6.q(bool);
        f0Var.k(this.F);
        this.f8104t = pVar.a();
        f0Var3.k(this.G);
        Executor executor = this.f8104t;
        if (executor != null) {
            executor.execute(new Runnable() { // from class: za.y
                @Override // java.lang.Runnable
                public final void run() {
                    ca.canadapost.module.addresscomplete.b.this.d0();
                }
            });
        }
    }

    private void W(AddressCompleteFindItem addressCompleteFindItem) {
        String str = (String) this.f8087c.f();
        if (str == null) {
            str = "";
        }
        this.f8103s.h(addressCompleteFindItem, str, new l() { // from class: za.a0
            @Override // dn.l
            public final Object invoke(Object obj) {
                n0 Z;
                Z = ca.canadapost.module.addresscomplete.b.this.Z((ResultWrapper) obj);
                return Z;
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ n0 Z(ResultWrapper resultWrapper) {
        if (resultWrapper instanceof ResultWrapper.Success) {
            AddressCompleteFindItem.AddressCompleteRetrieveItem addressCompleteRetrieveItem = (AddressCompleteFindItem.AddressCompleteRetrieveItem) ((ResultWrapper.Success) resultWrapper).getData();
            if (addressCompleteRetrieveItem == null) {
                return n0.f34904a;
            }
            this.f8094j.q(Boolean.FALSE);
            this.f8093i.q(addressCompleteRetrieveItem);
            this.f8098n.c(new AddressCompleteFindItem.a(this.f8106v, addressCompleteRetrieveItem));
            this.f8091g.q(new Event(Boolean.TRUE));
        }
        return n0.f34904a;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void a0(String str) {
        h0(str, null);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void c0(final AddressCompleteFindItem addressCompleteFindItem) {
        Executor executor;
        if (addressCompleteFindItem != null) {
            if (!addressCompleteFindItem.canRetrieve()) {
                h0(addressCompleteFindItem.Text, addressCompleteFindItem.Id);
                return;
            }
            if (addressCompleteFindItem.Id != null && "CA".equals(this.f8105u) && (executor = this.f8104t) != null) {
                executor.execute(new Runnable() { // from class: za.z
                    @Override // java.lang.Runnable
                    public final void run() {
                        ca.canadapost.module.addresscomplete.b.this.b0(addressCompleteFindItem);
                    }
                });
            }
            W(addressCompleteFindItem);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public /* synthetic */ void d0() {
        synchronized (this.f8088d) {
            if ("CA".equals(this.f8105u)) {
                List Y = Y();
                List list = (List) this.f8088d.f();
                if (list != null && list.size() == 0) {
                    this.f8088d.n(Y);
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.lifecycle.z0
    public void O() {
        this.f8087c.o(this.F);
        this.f8089e.o(this.G);
        super.O();
    }

    public void X() {
        if (this.C.f() != null && ((Boolean) this.C.f()).booleanValue()) {
            this.f8107w.q(Boolean.TRUE);
            this.C.q(Boolean.FALSE);
            this.D.q((Boolean) this.B.f());
        }
        String str = (String) this.f8087c.f();
        if (str == null || str.length() < 3) {
            return;
        }
        this.D.q(Boolean.FALSE);
    }

    protected List Y() {
        return this.f8103s.c();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void e0() {
        if (this.f8103s.g().f() != null) {
            this.A.q(Boolean.TRUE);
        } else {
            this.A.q(Boolean.FALSE);
        }
    }

    public void f0(boolean z10) {
        this.f8095k.q(Boolean.valueOf(z10));
    }

    public void g0(String str) {
        synchronized (this.f8088d) {
            this.f8105u = str;
            if (!"CA".equals(str)) {
                this.f8088d.n(new ArrayList());
            }
        }
    }

    protected void h0(String str, String str2) {
        if (str == null || str.length() < 3) {
            return;
        }
        this.f8109y.q(Boolean.TRUE);
        a aVar = this.H;
        aVar.f8113r = str;
        aVar.f8114s = str2;
        this.f8099o.a(aVar, aVar.f8112q == 0 ? 0 : 200);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    /* renamed from: i0, reason: merged with bridge method [inline-methods] */
    public void b0(AddressCompleteFindItem addressCompleteFindItem) {
        this.f8103s.b(addressCompleteFindItem);
    }
}
