package com.bytedance.ies.ugc.aweme.commercialize.intelligence.pitaya.handler;

import X.2Pr;
import X.2te;
import X.2th;
import X.C1163PbU;
import X.C1168PbZ;
import X.C1181Pbm;
import X.Q39;
import com.bytedance.covode.number.Covode;
import com.bytedance.pitaya.api.PTYTaskResultCallback;
import com.bytedance.pitaya.api.bean.PTYError;
import com.bytedance.pitaya.api.bean.PTYPackageInfo;
import com.bytedance.pitaya.api.bean.PTYTaskData;
import com.google.gson.j;
import com.google.gson.o;
import org.json.JSONObject;

public final class PrepareItemStructureHandler$internalHandle$1 implements PTYTaskResultCallback {
    public final /* synthetic */ C1181Pbm $callback;
    public final /* synthetic */ C1163PbU $chain;
    public final /* synthetic */ C1168PbZ $taskParams;

    static {
        Covode.recordClassIndex(30636);
    }

    public PrepareItemStructureHandler$internalHandle$1(C1181Pbm pbm, C1163PbU pbU, C1168PbZ pbZ) {
        this.$callback = pbm;
        this.$chain = pbU;
        this.$taskParams = pbZ;
    }

    public final void onResult(boolean z, PTYError pTYError, PTYTaskData pTYTaskData, PTYPackageInfo pTYPackageInfo) {
        Object obj;
        JSONObject params;
        if (pTYError == null || pTYError.getCode() == 0) {
            j jVar = null;
            try {
                o oVar = new o();
                if (pTYTaskData == null || (params = pTYTaskData.getParams()) == null) {
                    obj = null;
                } else {
                    obj = params.opt("result_json");
                }
                jVar = oVar.LIZ(String.valueOf(obj));
                2te.constructor-impl(2Pr.LIZ);
            } catch (Throwable th) {
                2te.constructor-impl(2th.LIZ(th));
            }
            this.$taskParams.LJ.put("json_template", jVar);
            this.$chain.LIZ(this.$callback);
            return;
        }
        C1181Pbm pbm = this.$callback;
        if (pbm != null) {
            int code = pTYError.getCode();
            String summary = pTYError.getSummary();
            if (summary == null) {
                summary = Q39.LIZJ;
            }
            pbm.LIZ(code, summary, this.$chain);
        }
    }
}
