package com.seewo.factoryaging.human;

import android.util.Log;
import com.google.gson.Gson;
import com.seewo.sdk.event.OSEvent;
import com.seewo.sdk.eventbus.OnEventOfOS;
import com.seewo.sdk.eventbus.ThreadMode;
import h.b.b.a.f;
import j.p0.d.r;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;

/* JADX INFO: compiled from: HumanPresenter.kt */
/* JADX INFO: loaded from: classes.dex */
public final class c extends com.seewo.factoryaging.human.a {

    /* JADX INFO: compiled from: HumanPresenter.kt */
    public /* synthetic */ class a {
        public static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[OSEvent.PersonIdentification.State.values().length];
            iArr[OSEvent.PersonIdentification.State.NO_FIELD.ordinal()] = 1;
            iArr[OSEvent.PersonIdentification.State.ALL_FIELD.ordinal()] = 2;
            a = iArr;
        }
    }

    private final boolean n() throws IOException {
        OkHttpClient okHttpClientBuild = f.d().callTimeout(3L, TimeUnit.SECONDS).build();
        Gson gson = new Gson();
        Request.Builder builder = new Request.Builder();
        String strA = f.a("/v1/device/detection/human");
        r.e(strA, "getFullUrl(URL_HUMAN)");
        Response responseExecute = okHttpClientBuild.newCall(builder.url(strA).get().build()).execute();
        ResponseBody responseBodyBody = responseExecute.body();
        if (responseBodyBody != null) {
            try {
                return ((com.seewo.factoryaging.r) gson.fromJson(responseBodyBody.string(), com.seewo.factoryaging.r.class)).a();
            } catch (Throwable th) {
                Log.e("HumanPresenter", "isHasHuman format error", th);
                return false;
            }
        }
        Log.e("HumanPresenter", "isHasHuman error" + responseExecute);
        return false;
    }

    @Override // com.seewo.factoryaging.human.a
    public void l() {
        h.c.c.c.d().l(this);
    }

    @Override // com.seewo.factoryaging.human.a
    public void m() {
        if (n()) {
            Log.d("HumanPresenter", "init has human");
            b bVarI = i();
            r.c(bVarI);
            bVarI.x();
        }
        h.c.c.c.d().j(this);
    }

    @OnEventOfOS(threadMode = ThreadMode.MAIN)
    public final void onEvent(OSEvent.PersonIdentification personIdentification) {
        r.f(personIdentification, "event");
        Log.d("HumanPresenter", "PIR trigger" + personIdentification.state.name());
        OSEvent.PersonIdentification.State state = personIdentification.state;
        int i2 = state == null ? -1 : a.a[state.ordinal()];
        if (i2 == 1) {
            Log.d("HumanPresenter", "NO_FIELD human false");
            b bVarI = i();
            r.c(bVarI);
            bVarI.D();
            return;
        }
        if (i2 != 2) {
            return;
        }
        Log.d("HumanPresenter", "ALL_FIELD human true");
        b bVarI2 = i();
        r.c(bVarI2);
        bVarI2.x();
    }
}
