package com.bytedance.sdk.openadsdk.core.onz.lb;

import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import com.bytedance.sdk.openadsdk.core.gof;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.utils.bx;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import u.a;

/* JADX INFO: loaded from: classes2.dex */
public class lb {
    private static SimpleDateFormat fm = null;
    private static boolean yz = false;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    @NonNull
    private final Map<ro, String> f7250lb;

    @NonNull
    private final List<String> ro;

    public lb(@NonNull List<String> list, lse lseVar) {
        int iIe;
        this.ro = list;
        HashMap map = new HashMap();
        this.f7250lb = map;
        map.put(ro.CACHEBUSTING, lb());
        map.put(ro.TIMESTAMP, ro());
        map.put(ro.APPBUNDLE, gof.fm().getPackageName());
        ro roVar = ro.PLAYERSTATE;
        map.put(roVar, "");
        if (lseVar != null && ((iIe = lseVar.ie()) == 3 || iIe == 7 || iIe == 8)) {
            map.put(roVar, "fullscreen");
        }
        map.put(ro.SERVERSIDE, SessionDescription.SUPPORTED_SDP_VERSION);
    }

    @NonNull
    private String lb() {
        return String.format(Locale.US, "%08d", Long.valueOf(Math.round(Math.random() * 1.0E8d)));
    }

    private String ro() {
        if (fm == null) {
            fm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX", Locale.getDefault());
        }
        String str = fm.format(new Date());
        if (!yz) {
            return str;
        }
        int iNt = bx.nt();
        if (iNt < 0) {
            if (iNt > -10) {
                StringBuilder sbD = a.d(str, "-0");
                sbD.append(-iNt);
                return sbD.toString();
            }
            return str + iNt;
        }
        if (iNt < 10) {
            return str + "+0" + iNt;
        }
        return str + "+" + iNt;
    }

    @NonNull
    public List<String> fm() {
        ArrayList arrayList = new ArrayList();
        for (String strReplaceAll : this.ro) {
            if (!TextUtils.isEmpty(strReplaceAll)) {
                for (ro roVar : ro.values()) {
                    String str = this.f7250lb.get(roVar);
                    if (str == null) {
                        str = "";
                    }
                    strReplaceAll = roVar == ro.__MRC_IMPRESSION_ID__ ? strReplaceAll.replaceAll(roVar.name(), str) : strReplaceAll.replaceAll("\\[" + roVar.name() + "\\]", str);
                }
                arrayList.add(strReplaceAll);
            }
        }
        return arrayList;
    }

    @NonNull
    public lb fm(@Nullable com.bytedance.sdk.openadsdk.core.onz.fm.fm fmVar) {
        if (fmVar != null) {
            this.f7250lb.put(ro.ERRORCODE, fmVar.fm());
        }
        return this;
    }

    @NonNull
    public lb fm(@Nullable long j10) {
        if (j10 >= 0) {
            String strRo = ro(j10);
            if (!TextUtils.isEmpty(strRo)) {
                this.f7250lb.put(ro.CONTENTPLAYHEAD, strRo);
            }
        }
        return this;
    }

    @NonNull
    public lb ro(@Nullable String str) {
        if (!TextUtils.isEmpty(str)) {
            try {
                str = URLEncoder.encode(str, "UTF-8");
            } catch (Throwable unused) {
            }
            this.f7250lb.put(ro.ASSETURI, str);
        }
        return this;
    }

    public lb fm(String str) {
        if (!TextUtils.isEmpty(str)) {
            this.f7250lb.put(ro.__MRC_IMPRESSION_ID__, str);
        }
        return this;
    }

    @NonNull
    private String ro(long j10) {
        Locale locale = Locale.getDefault();
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        return String.format(locale, "%02d:%02d:%02d.%03d", Long.valueOf(timeUnit.toHours(j10)), Long.valueOf(timeUnit.toMinutes(j10) % TimeUnit.HOURS.toMinutes(1L)), Long.valueOf(timeUnit.toSeconds(j10) % TimeUnit.MINUTES.toSeconds(1L)), Long.valueOf(j10 % 1000));
    }
}
