package com.bytedance.sdk.openadsdk.core.model;

import android.util.SparseArray;
import androidx.annotation.NonNull;
import com.bytedance.sdk.openadsdk.core.lb.lb;
import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class duv {
    private final float ajl;
    private final SparseArray<lb.fm> dsz;
    private final int duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private final int f7159ef;
    private final JSONObject fhx;
    private final int[] fm;
    private final String irt;
    private final float jnr;
    private final int ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private final float f7160lb;
    private final int onz;
    private final JSONObject qhl;
    private final int[] ro;
    private final int vt;
    private final long wsy;
    private final long wu;
    private final float yz;

    public static class fm {
        private float ajl;
        private int dsz;
        private int duv;

        /* JADX INFO: renamed from: ef, reason: collision with root package name */
        private float f7161ef;
        private SparseArray<lb.fm> fhx;
        float fm;
        private int gof;
        private JSONObject gqi;
        private int irt;
        private long jnr;
        private int[] ku;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        float f7162lb;
        private int onz;
        private String qhl;
        int ro;
        private int[] vt;
        private JSONObject wey;
        private float wsy;
        private float wu;
        private long yz;

        public fm ajl(float f10) {
            this.f7161ef = f10;
            return this;
        }

        public fm fm(float f10) {
            this.fm = f10;
            return this;
        }

        public fm jnr(float f10) {
            this.wu = f10;
            return this;
        }

        public fm lb(float f10) {
            this.ajl = f10;
            return this;
        }

        public fm ro(float f10) {
            this.f7162lb = f10;
            return this;
        }

        public fm yz(float f10) {
            this.wsy = f10;
            return this;
        }

        public fm ajl(int i10) {
            this.onz = i10;
            return this;
        }

        public fm fm(int i10) {
            this.gof = i10;
            return this;
        }

        public fm jnr(int i10) {
            this.dsz = i10;
            return this;
        }

        public fm lb(int i10) {
            this.ro = i10;
            return this;
        }

        public fm ro(int i10) {
            this.irt = i10;
            return this;
        }

        public fm yz(int i10) {
            this.duv = i10;
            return this;
        }

        public fm fm(long j10) {
            this.yz = j10;
            return this;
        }

        public fm ro(long j10) {
            this.jnr = j10;
            return this;
        }

        public fm fm(SparseArray<lb.fm> sparseArray) {
            this.fhx = sparseArray;
            return this;
        }

        public fm ro(JSONObject jSONObject) {
            this.wey = jSONObject;
            return this;
        }

        public fm fm(String str) {
            this.qhl = str;
            return this;
        }

        public fm ro(int[] iArr) {
            this.ku = iArr;
            return this;
        }

        public fm fm(JSONObject jSONObject) {
            this.gqi = jSONObject;
            return this;
        }

        public fm fm(int[] iArr) {
            this.vt = iArr;
            return this;
        }

        public duv fm() {
            return new duv(this);
        }
    }

    public JSONObject fm() {
        JSONObject jSONObject = new JSONObject();
        try {
            JSONObject jSONObject2 = this.qhl;
            if (jSONObject2 != null) {
                try {
                    Iterator<String> itKeys = jSONObject2.keys();
                    while (itKeys.hasNext()) {
                        String next = itKeys.next();
                        jSONObject.putOpt(next, this.qhl.opt(next));
                    }
                } catch (Exception unused) {
                }
            }
            int[] iArr = this.fm;
            if (iArr != null && iArr.length == 2) {
                jSONObject.putOpt("ad_x", Integer.valueOf(iArr[0])).putOpt("ad_y", Integer.valueOf(this.fm[1]));
            }
            int[] iArr2 = this.ro;
            if (iArr2 != null && iArr2.length == 2) {
                jSONObject.putOpt("width", Integer.valueOf(iArr2[0])).putOpt("height", Integer.valueOf(this.ro[1]));
            }
            jSONObject.putOpt("down_x", Float.toString(this.f7160lb)).putOpt("down_y", Float.toString(this.yz)).putOpt("up_x", Float.toString(this.jnr)).putOpt("up_y", Float.toString(this.ajl)).putOpt("down_time", Long.valueOf(this.wsy)).putOpt("up_time", Long.valueOf(this.wu)).putOpt("toolType", Integer.valueOf(this.f7159ef)).putOpt("deviceId", Integer.valueOf(this.vt)).putOpt("source", Integer.valueOf(this.ku)).putOpt("ft", fm(this.dsz, this.duv)).putOpt("click_area_type", this.irt);
            int i10 = this.onz;
            if (i10 > 0) {
                jSONObject.putOpt("areaType", Integer.valueOf(i10));
            }
            JSONObject jSONObject3 = this.fhx;
            if (jSONObject3 != null) {
                jSONObject.putOpt("rectInfo", jSONObject3);
            }
        } catch (Exception unused2) {
        }
        return jSONObject;
    }

    private duv(@NonNull fm fmVar) {
        this.fm = fmVar.vt;
        this.ro = fmVar.ku;
        this.f7160lb = fmVar.f7161ef;
        this.yz = fmVar.wu;
        this.jnr = fmVar.wsy;
        this.ajl = fmVar.ajl;
        this.wsy = fmVar.jnr;
        this.wu = fmVar.yz;
        this.f7159ef = fmVar.duv;
        this.vt = fmVar.dsz;
        this.ku = fmVar.onz;
        this.duv = fmVar.irt;
        this.dsz = fmVar.fhx;
        this.irt = fmVar.qhl;
        this.onz = fmVar.gof;
        this.fhx = fmVar.gqi;
        this.qhl = fmVar.wey;
    }

    public static JSONObject fm(SparseArray<lb.fm> sparseArray, int i10) {
        try {
            JSONObject jSONObject = new JSONObject();
            JSONArray jSONArray = new JSONArray();
            if (sparseArray != null) {
                for (int i11 = 0; i11 < sparseArray.size(); i11++) {
                    lb.fm fmVarValueAt = sparseArray.valueAt(i11);
                    if (fmVarValueAt != null) {
                        JSONObject jSONObject2 = new JSONObject();
                        jSONObject2.putOpt("force", Double.valueOf(fmVarValueAt.f7151lb)).putOpt("mr", Double.valueOf(fmVarValueAt.ro)).putOpt("phase", Integer.valueOf(fmVarValueAt.fm)).putOpt("ts", Long.valueOf(fmVarValueAt.yz));
                        jSONArray.put(jSONObject2);
                        jSONObject.putOpt("ftc", Integer.valueOf(i10)).putOpt("info", jSONArray);
                    }
                }
            }
            return jSONObject;
        } catch (JSONException unused) {
            return null;
        }
    }
}
