package com.bytedance.geckox.model;

import X.0HH;
import X.AnonymousClass837;
import X.AnonymousClass83D;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.google.gson.a.c;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;

public class UpdatePackage {
    @c(LIZ = "access_key")
    public String accessKey;
    public String apiVersion;
    @c(LIZ = "biz_extra")
    public Map<String, String> bizExtra;
    @c(LIZ = "channel")
    public String channel;
    @c(LIZ = "channel_index")
    public int channelIndex;
    @c(LIZ = "content")
    public Content content;
    @c(LIZ = "from")
    public List<String> from;
    @c(LIZ = "group_name")
    public String groupName;
    @c(LIZ = "is_zstd")
    public boolean isZstd;
    public boolean isZstdFallback;
    public long localVersion;
    public long localVersionOld;
    public String logId;
    public int notUsePatchReason;
    @c(LIZ = "package_type")
    public int packageType;
    public AnonymousClass837 statisticModel;
    public boolean updateWithPatch;
    public boolean usePatched;
    @c(LIZ = "package_version")
    public long version;

    public static final class FileType {
        static {
            Covode.recordClassIndex(26515);
        }
    }

    static {
        Covode.recordClassIndex(26512);
    }

    public static class Content {
        @c(LIZ = "package")
        public Package fullPackage;
        @c(LIZ = "patch")
        public Package patch;
        @c(LIZ = "strategies")
        public Strategy strategy;

        static {
            Covode.recordClassIndex(26513);
        }

        public Strategy getStrategy() {
            return this.strategy;
        }
    }

    public static class Fallback {
        @c(LIZ = "md5")
        public String md5;
        @c(LIZ = "url_list")
        public List<String> urlList;

        static {
            Covode.recordClassIndex(26514);
        }

        public String getMd5() {
            return this.md5;
        }

        public List<String> getUrlList() {
            return this.urlList;
        }
    }

    public static class Package {
        @c(LIZ = "decompress_md5")
        public String decompressMd5;
        @c(LIZ = "fallback")
        public Fallback fallback;
        @c(LIZ = "id")
        public long id;
        @c(LIZ = "size")
        public long length;
        @c(LIZ = "md5")
        public String md5;
        public String url;
        @c(LIZ = "url_list")
        public List<String> urlList;

        static {
            Covode.recordClassIndex(26516);
        }

        public Package() {
        }

        public String getDecompressMd5() {
            return this.decompressMd5;
        }

        public Fallback getFallback() {
            return this.fallback;
        }

        public long getId() {
            return this.id;
        }

        public long getLength() {
            return this.length;
        }

        public String getMd5() {
            return this.md5;
        }

        public String getUrl() {
            return this.url;
        }

        public List<String> getUrlList() {
            return this.urlList;
        }

        public String toString() {
            return "Package{url='" + this.url + '\'' + ", md5='" + this.md5 + '\'' + '}';
        }

        public void setId(int i) {
            this.id = (long) i;
        }

        public void setLength(long j) {
            this.length = j;
        }

        public void setMd5(String str) {
            this.md5 = str;
        }

        public void setUrl(String str) {
            this.url = str;
        }

        public void setUrlList(List<String> list) {
            this.urlList = list;
        }

        public Package(long j, List<String> list, String str) {
            this.id = j;
            this.urlList = list;
            this.md5 = str;
        }
    }

    public static class Strategy {
        @c(LIZ = "del_if_download_failed")
        public int deleteIfFail;
        @c(LIZ = "del_old_pkg_before_download")
        public int deleteOldPackageBeforeDownload;
        @c(LIZ = "need_unzip")
        public int needUnzip;

        static {
            Covode.recordClassIndex(26517);
        }

        public int getDeleteIfFail() {
            return this.deleteIfFail;
        }

        public int getDeleteOldPackageBeforeDownload() {
            return this.deleteOldPackageBeforeDownload;
        }

        public int getNeedUnzip() {
            return this.needUnzip;
        }

        public void setDeleteIfFail(int i) {
            this.deleteIfFail = i;
        }

        public void setDeleteOldPackageBeforeDownload(int i) {
            this.deleteOldPackageBeforeDownload = i;
        }

        public void setNeedUnzip(int i) {
            this.needUnzip = i;
        }
    }

    public String getAccessKey() {
        return this.accessKey;
    }

    public Map<String, String> getBizExtra() {
        return this.bizExtra;
    }

    public String getChannel() {
        return this.channel;
    }

    public int getChannelIndex() {
        return this.channelIndex;
    }

    public Content getContent() {
        return this.content;
    }

    public List<String> getFrom() {
        return this.from;
    }

    public String getGroupName() {
        return this.groupName;
    }

    public boolean getIsZstd() {
        return this.isZstd;
    }

    public long getLocalVersion() {
        return this.localVersion;
    }

    public int getPackageType() {
        return this.packageType;
    }

    public AnonymousClass837 getStatisticModel() {
        return this.statisticModel;
    }

    public boolean getUpdateWithPatch() {
        return this.updateWithPatch;
    }

    public long getVersion() {
        return this.version;
    }

    public boolean getZstdFallback() {
        return this.isZstdFallback;
    }

    public Package getFullPackage() {
        return this.content.fullPackage;
    }

    public Package getPatch() {
        return this.content.patch;
    }

    public Strategy getStrategy() {
        return this.content.strategy;
    }

    public UpdatePackage() {
        this.content = new Content();
        this.groupName = "default";
    }

    public Package getPackage() {
        if (this.updateWithPatch) {
            return this.content.patch;
        }
        return this.content.fullPackage;
    }

    public boolean hasFallback() {
        if (this.content.fullPackage.fallback != null) {
            return true;
        }
        return false;
    }

    public boolean isFullUpdate() {
        if (getFullPackage() == null || getFullPackage().getUrlList().size() <= 0) {
            return false;
        }
        return true;
    }

    public boolean isLastStep() {
        if (this.isZstdFallback) {
            return true;
        }
        if (!isPatchUpdate() && !hasFallback()) {
            return true;
        }
        return false;
    }

    public boolean isPatchUpdate() {
        if (getPatch() == null || getPatch().getUrlList().size() <= 0) {
            return false;
        }
        return true;
    }

    public String toString() {
        return 0HH.LIZ("ak:%s, channel:%s, version:%d, packageType:%d, isZstd:%b, updateWithPatch:%b", new Object[]{this.accessKey, this.channel, Long.valueOf(this.version), Integer.valueOf(this.packageType), Boolean.valueOf(this.isZstd), Boolean.valueOf(this.updateWithPatch)});
    }

    public UpdatePackage fallbackInstance() {
        UpdatePackage updatePackage = new UpdatePackage();
        updatePackage.groupName = this.groupName;
        updatePackage.channelIndex = this.channelIndex;
        updatePackage.version = this.version;
        updatePackage.channel = this.channel;
        updatePackage.accessKey = this.accessKey;
        updatePackage.from = this.from;
        updatePackage.packageType = this.packageType;
        updatePackage.statisticModel = this.statisticModel;
        updatePackage.apiVersion = this.apiVersion;
        updatePackage.logId = this.logId;
        updatePackage.localVersion = this.localVersion;
        updatePackage.localVersionOld = this.localVersionOld;
        updatePackage.notUsePatchReason = this.notUsePatchReason;
        updatePackage.usePatched = this.usePatched;
        updatePackage.isZstd = false;
        updatePackage.isZstdFallback = true;
        Content content2 = new Content();
        updatePackage.content = content2;
        content2.strategy = this.content.strategy;
        Package packageR = this.content.fullPackage;
        Package packageR2 = new Package();
        packageR2.id = packageR.id;
        packageR2.urlList = packageR.fallback.urlList;
        packageR2.md5 = packageR.fallback.md5;
        updatePackage.content.fullPackage = packageR2;
        return updatePackage;
    }

    public void setAccessKey(String str) {
        this.accessKey = str;
    }

    public void setApiVersion(String str) {
        this.apiVersion = str;
    }

    public void setChannel(String str) {
        this.channel = str;
    }

    public void setChannelIndex(int i) {
        this.channelIndex = i;
    }

    public void setContent(Content content2) {
        this.content = content2;
    }

    public void setFrom(List<String> list) {
        this.from = list;
    }

    public void setGroupName(String str) {
        this.groupName = str;
    }

    public void setLocalVersion(long j) {
        this.localVersion = j;
    }

    public void setLocalVersionOld(long j) {
        this.localVersionOld = j;
    }

    public void setLogId(String str) {
        this.logId = str;
    }

    public void setNotUsePatchReason(int i) {
        this.notUsePatchReason = i;
    }

    public void setPackageType(int i) {
        this.packageType = i;
    }

    public void setStatisticModel(AnonymousClass837 r1) {
        this.statisticModel = r1;
    }

    public void setVersion(long j) {
        this.version = j;
    }

    public void setZstdFallback(boolean z) {
        this.isZstdFallback = z;
    }

    public void setFullPackage(Package packageR) {
        this.content.fullPackage = packageR;
    }

    public void setPatch(Package packageR) {
        this.content.patch = packageR;
    }

    public void setStrategy(Strategy strategy) {
        this.content.strategy = strategy;
    }

    public void setUpdateWithPatch(boolean z) {
        this.updateWithPatch = z;
        if (z) {
            this.usePatched = true;
        }
    }

    public void putStatisticModelToJson(JSONObject jSONObject) {
        int i;
        jSONObject.put("access_key", this.accessKey);
        jSONObject.put("group_name", this.groupName);
        jSONObject.put("channel", this.channel);
        jSONObject.put("id", getFullPackage().getId());
        if (this.isZstd || this.isZstdFallback) {
            i = 1;
        } else {
            i = 0;
        }
        jSONObject.put("is_zstd", i);
        jSONObject.put("api_version", this.apiVersion);
        if (!TextUtils.isEmpty(this.logId)) {
            jSONObject.put("x_tt_logid", this.logId);
        }
        long j = this.localVersion;
        if (j != 0) {
            jSONObject.put("local_version", j);
        }
        if (getPatch() != null) {
            jSONObject.put("patch_id", getPatch().getId());
        }
        long j2 = this.localVersionOld;
        if (j2 != 0) {
            jSONObject.put("local_version_old", j2);
        }
        int i2 = this.packageType;
        if (i2 > 0) {
            jSONObject.put("package_type", i2);
        }
        int i3 = this.notUsePatchReason;
        if (i3 != 0) {
            jSONObject.put("not_use_patch_reason", i3);
        } else if (this.localVersion != 0 && !this.usePatched) {
            jSONObject.put("not_use_patch_reason", 10);
        }
        AnonymousClass837 r2 = this.statisticModel;
        if (r2 != null) {
            jSONObject.put("req_type", r2.LIZIZ);
            jSONObject.put("update_priority", r2.LIZ);
            jSONObject.put("update_result", r2.LIZLLL ^ true ? 1 : 0);
            if (r2.LIZJ != 0) {
                jSONObject.put("sync_task_id", r2.LIZJ);
            }
            if (r2.LJ) {
                jSONObject.put("create_by_error", r2.LJ);
            }
            if (r2.LJFF > 0) {
                jSONObject.put("dur_total", r2.LJFF);
            }
            if (r2.LJI > 0) {
                jSONObject.put("dur_last_stage", r2.LJI);
            }
            if (r2.LJII > 0) {
                jSONObject.put("dur_download", r2.LJII);
            }
            if (r2.LJIIIIZZ > 0) {
                jSONObject.put("dur_download_last_time", r2.LJIIIIZZ);
            }
            if (r2.LJIIIZ > 0) {
                jSONObject.put("dur_active", r2.LJIIIZ);
            }
            if (r2.LJIIJ > 0) {
                jSONObject.put("dur_unzip", r2.LJIIJ);
            }
            if (r2.LJIIJJI > 0) {
                jSONObject.put("dur_decompress_zstd", r2.LJIIJJI);
            }
            if (r2.LJIIL > 0) {
                jSONObject.put("dur_bytepatch", r2.LJIIL);
            }
            if (r2.LJIILIIL > 0) {
                jSONObject.put("dur_zip_patch", r2.LJIILIIL);
            }
            if (r2.LJIILJJIL > 0) {
                jSONObject.put("dur_from_cold_start", r2.LJIILJJIL);
            }
            for (AnonymousClass83D next : r2.LJIJJLI.values()) {
                jSONObject.put(next.LIZ + "result", next.LIZIZ ^ true ? 1 : 0);
                jSONObject.put(next.LIZ + "url", next.LJ);
                if (!TextUtils.isEmpty(next.LIZLLL)) {
                    jSONObject.put(next.LIZ + "err_msg", next.LIZLLL);
                }
                if (next.LIZJ != 0) {
                    jSONObject.put(next.LIZ + "err_code", next.LIZJ);
                }
                if (next.LJFF > 0) {
                    jSONObject.put(next.LIZ + "download_failed_times", next.LJFF);
                }
                if (next.LJI) {
                    jSONObject.put(next.LIZ + "create_by_error", 1);
                }
            }
        }
        if (this.updateWithPatch) {
            if (getPatch() != null) {
                jSONObject.put("package_size", getPatch().getLength());
            }
        } else if (getFullPackage() != null) {
            jSONObject.put("package_size", getFullPackage().getLength());
        }
    }

    public UpdatePackage(long j, String str, Package packageR, Package packageR2) {
        this.version = j;
        this.channel = str;
        Content content2 = new Content();
        this.content = content2;
        content2.fullPackage = packageR;
        this.content.patch = packageR2;
        this.groupName = "default";
    }
}
