package com.ss.android.ugc.aweme.shortvideo;

import X.AnonymousClass5RN;
import X.C35946aW;
import X.C51476zZ;
import X.C517970f;
import X.Nsg;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.google.gson.b.a;
import com.google.gson.m;
import com.ss.android.ugc.aweme.shortvideo.WorkSpace.Workspace;
import com.ss.android.ugc.aweme.shortvideo.model.ExtractFramesModel;
import com.ss.android.ugc.aweme.shortvideo.model.GameDuetResource;
import com.ss.android.ugc.aweme.shortvideo.ui.TimeSpeedModelExtension;
import com.ss.android.ugc.aweme.sticker.model.BackgroundVideo;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class CameraComponentModel implements Parcelable {
    public static final Parcelable.Creator<CameraComponentModel> CREATOR = new Parcelable.Creator<CameraComponentModel>() {
        static {
            Covode.recordClassIndex(108130);
        }

        public final /* bridge */ /* synthetic */ Object[] newArray(int i) {
            return new CameraComponentModel[i];
        }

        public final /* synthetic */ Object createFromParcel(Parcel parcel) {
            return new CameraComponentModel(parcel, (byte) 0);
        }
    };
    public final int LIZ;
    public long LIZIZ;
    public int LIZJ;
    public int LIZLLL;
    public int LJ;
    public C517970f LJFF;
    public long LJI;
    public Workspace LJII;
    public boolean LJIIIIZZ;
    public long LJIIIZ;
    public long LJIIJ;
    public boolean LJIIJJI;
    public boolean LJIIL;
    public ClientCherEffectParam LJIILIIL;
    public DuetContext LJIILJJIL;
    public int LJIILL;
    public int LJIILLIIL;
    public BackgroundVideo LJIIZILJ;
    public boolean LJIJ;
    public boolean LJIJI;
    public boolean LJIJJ;
    public int LJIJJLI;
    public GameDuetResource LJIL;
    public ExtractFramesModel LJJ;
    public C51476zZ LJJI;
    public String LJJIFFI;
    public boolean LJJII;
    public float LJJIII;
    public boolean LJJIIJ;
    public int LJJIIJZLJL;
    public String LJJIIZ;
    public int LJJIIZI;
    public Map<String, Object> LJJIJ;
    public boolean LJJIJIIJI;
    public RecordContext LJJIJIIJIL;
    public boolean LJJIJIL;
    public C517970f LJJIJL;

    public int describeContents() {
        return 0;
    }

    static {
        Covode.recordClassIndex(108128);
    }

    public final boolean LIZJ() {
        C51476zZ r0 = this.LJJI;
        if (r0 == null || !r0.LIZJ()) {
            return false;
        }
        return true;
    }

    public final C517970f LIZLLL() {
        if (this.LJIIIIZZ) {
            return this.LJJIJL;
        }
        return this.LJFF;
    }

    public final String LJFF() {
        if (LIZ()) {
            return this.LJII.LIZJ();
        }
        return null;
    }

    public final long LJIIIIZZ() {
        if (this.LJIIIIZZ) {
            return this.LJIIIZ;
        }
        return this.LJI;
    }

    public final long LJIIJJI() {
        if (this.LJIIIIZZ) {
            return this.LJIIJ;
        }
        return this.LIZIZ;
    }

    public final boolean LJIIL() {
        if (!this.LJJIJIL || LIZIZ()) {
            return false;
        }
        return true;
    }

    public final boolean LIZ() {
        Workspace workspace = this.LJII;
        if (workspace == null || workspace.LIZJ() == null || LIZIZ()) {
            return false;
        }
        return true;
    }

    public final boolean LIZIZ() {
        if (TextUtils.isEmpty(this.LJIILJJIL.LIZJ) || TextUtils.isEmpty(this.LJIILJJIL.LIZLLL)) {
            return false;
        }
        return true;
    }

    public final TimeSpeedModelExtension LJ() {
        C517970f LIZLLL2 = LIZLLL();
        if (LIZLLL2.isEmpty()) {
            return null;
        }
        return (TimeSpeedModelExtension) LIZLLL2.get(LIZLLL2.size() - 1);
    }

    public final String LJI() {
        String LJFF2 = LJFF();
        if (LJFF2 != null) {
            return LJFF2;
        }
        if (this.LJIILJJIL.LIZLLL != null) {
            return this.LJIILJJIL.LIZLLL;
        }
        return null;
    }

    public final boolean LJIIIZ() {
        Iterator it = this.LJFF.iterator();
        while (it.hasNext()) {
            if (((TimeSpeedModelExtension) it.next()).getBackgroundVideo() != null) {
                return true;
            }
        }
        return false;
    }

    public CameraComponentModel() {
        this.LJFF = new C517970f();
        this.LJJIJL = new C517970f();
        this.LJI = 0;
        this.LJIIIZ = 0;
        this.LJIIJJI = false;
        this.LJIIL = false;
        this.LJIILJJIL = new DuetContext((byte) 0);
        this.LJIJI = true;
        this.LJIJJ = true;
        this.LJJIII = -1.0f;
        this.LJJIIZI = 0;
        this.LJJIJIIJI = false;
        this.LJJIJIIJIL = new RecordContext();
        this.LJJIJIL = false;
        this.LIZ = 0;
    }

    public final C517970f LJIIJ() {
        if (!this.LJIIIIZZ || AnonymousClass5RN.LIZ(this.LJJIJL)) {
            return this.LJFF;
        }
        C517970f r2 = new C517970f(this.LJFF);
        r2.remove(this.LJJI.LIZIZ());
        r2.addAll(this.LJJI.LIZIZ(), this.LJJIJL);
        return r2;
    }

    public final long LJII() {
        if (this.LJIIIIZZ) {
            return this.LJJI.LIZ() + ((long) this.LJIILL);
        }
        Iterator it = this.LJFF.iterator();
        while (it.hasNext()) {
            if (((TimeSpeedModelExtension) it.next()).getLibraryVideo() != null) {
                long j = 0;
                Iterator it2 = this.LJFF.iterator();
                while (it2.hasNext()) {
                    TimeSpeedModelExtension timeSpeedModelExtension = (TimeSpeedModelExtension) it2.next();
                    if (timeSpeedModelExtension.getLibraryVideo() != null) {
                        j += timeSpeedModelExtension.getLibraryVideo().getAudioDuration();
                    }
                }
                return j + ((long) this.LJIILL);
            }
        }
        return (long) this.LJIILL;
    }

    public final void LIZ(long j) {
        if (this.LJIIIIZZ) {
            this.LJIIIZ = j;
        } else {
            this.LJI = j;
        }
    }

    public static ArrayList<TimeSpeedModelExtension> LIZ(String str) {
        try {
            ArrayList arrayList = (ArrayList) Nsg.LJIIIZ.LIZJ().LIZ(str, new a<ArrayList<m>>() {
                static {
                    Covode.recordClassIndex(108129);
                }
            }.type);
            ArrayList<TimeSpeedModelExtension> arrayList2 = new ArrayList<>(arrayList.size());
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                arrayList2.add(TimeSpeedModelExtension.fromJson(Nsg.LJIIIZ.LIZJ(), (m) it.next()));
            }
            return arrayList2;
        } catch (Exception unused) {
            return LIZIZ(str);
        }
    }

    public static ArrayList<TimeSpeedModelExtension> LIZIZ(String str) {
        ArrayList<TimeSpeedModelExtension> arrayList = new ArrayList<>();
        String str2 = str;
        if (TextUtils.isEmpty(str2)) {
            return arrayList;
        }
        String[] split = str2.split("\\$");
        if (split.length > 0) {
            for (String split2 : split) {
                String[] split3 = split2.split(",");
                if (split3.length == 2) {
                    try {
                        arrayList.add(new TimeSpeedModelExtension(Integer.parseInt(split3[0]), (double) Float.parseFloat(split3[1]), (String) null, (List<AVChallenge>) null, (List<String>) null));
                    } catch (Exception unused) {
                    }
                }
                if (split3.length == 3) {
                    try {
                        arrayList.add(new TimeSpeedModelExtension(Integer.parseInt(split3[0]), (double) Float.parseFloat(split3[1]), split3[2], (List<AVChallenge>) null, (List<String>) null));
                    } catch (Exception unused2) {
                    }
                }
            }
        }
        return arrayList;
    }

    public CameraComponentModel(Parcel parcel) {
        boolean z;
        boolean z2;
        boolean z3;
        boolean z4;
        boolean z5;
        this.LJFF = new C517970f();
        this.LJJIJL = new C517970f();
        this.LJI = 0;
        this.LJIIIZ = 0;
        boolean z6 = false;
        this.LJIIJJI = false;
        this.LJIIL = false;
        this.LJIILJJIL = new DuetContext((byte) 0);
        this.LJIJI = true;
        this.LJIJJ = true;
        this.LJJIII = -1.0f;
        this.LJJIIZI = 0;
        this.LJJIJIIJI = false;
        this.LJJIJIIJIL = new RecordContext();
        this.LJJIJIL = false;
        this.LIZ = parcel.readInt();
        this.LIZIZ = parcel.readLong();
        this.LJJIFFI = parcel.readString();
        this.LJIILL = parcel.readInt();
        this.LIZJ = parcel.readInt();
        this.LIZLLL = parcel.readInt();
        this.LJII = (Workspace) parcel.readParcelable(Workspace.class.getClassLoader());
        this.LJFF = new C517970f(LIZ(parcel.readString()));
        this.LJI = parcel.readLong();
        this.LJ = parcel.readInt();
        if (parcel.readInt() == 1) {
            z = true;
        } else {
            z = false;
        }
        this.LJJIIJ = z;
        this.LJJIIJZLJL = parcel.readInt();
        this.LJJIIZ = parcel.readString();
        this.LJJIIZI = parcel.readInt();
        this.LJIILJJIL = (DuetContext) parcel.readParcelable(DuetContext.class.getClassLoader());
        this.LJJIJIIJIL = (RecordContext) parcel.readParcelable(RecordContext.class.getClassLoader());
        if (parcel.readByte() != 0) {
            z2 = true;
        } else {
            z2 = false;
        }
        this.LJIJI = z2;
        if (parcel.readByte() != 0) {
            z3 = true;
        } else {
            z3 = false;
        }
        this.LJIJJ = z3;
        if (parcel.readByte() != 0) {
            z4 = true;
        } else {
            z4 = false;
        }
        this.LJIIJJI = z4;
        this.LJIJJLI = parcel.readInt();
        this.LJIL = parcel.readParcelable(GameDuetResource.class.getClassLoader());
        this.LJJ = (ExtractFramesModel) parcel.readSerializable();
        this.LJIILIIL = (ClientCherEffectParam) parcel.readParcelable(ClientCherEffectParam.class.getClassLoader());
        if (parcel.readByte() != 0) {
            z5 = true;
        } else {
            z5 = false;
        }
        this.LJJII = z5;
        this.LJJIII = parcel.readFloat();
        this.LJIJ = parcel.readByte() != 0 ? true : z6;
    }

    public /* synthetic */ CameraComponentModel(Parcel parcel, byte b) {
        this(parcel);
    }

    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(this.LIZ);
        parcel.writeLong(this.LIZIZ);
        parcel.writeString(this.LJJIFFI);
        parcel.writeInt(this.LJIILL);
        parcel.writeInt(this.LIZJ);
        parcel.writeInt(this.LIZLLL);
        parcel.writeParcelable(this.LJII, i);
        parcel.writeString(C35946aW.LIZ(this.LJFF));
        parcel.writeLong(this.LJI);
        parcel.writeInt(this.LJ);
        parcel.writeInt(this.LJJIIJ ? 1 : 0);
        parcel.writeInt(this.LJJIIJZLJL);
        parcel.writeString(this.LJJIIZ);
        parcel.writeInt(this.LJJIIZI);
        parcel.writeParcelable(this.LJIILJJIL, i);
        parcel.writeParcelable(this.LJJIJIIJIL, i);
        parcel.writeByte(this.LJIJI ? (byte) 1 : 0);
        parcel.writeByte(this.LJIJJ ? (byte) 1 : 0);
        parcel.writeByte(this.LJIIJJI ? (byte) 1 : 0);
        parcel.writeInt(this.LJIJJLI);
        parcel.writeParcelable(this.LJIL, i);
        parcel.writeSerializable(this.LJJ);
        parcel.writeParcelable(this.LJIILIIL, i);
        parcel.writeByte(this.LJJII ? (byte) 1 : 0);
        parcel.writeFloat(this.LJJIII);
        parcel.writeByte(this.LJIJ ? (byte) 1 : 0);
    }

    public CameraComponentModel(int i, String str, int i2) {
        this.LJFF = new C517970f();
        this.LJJIJL = new C517970f();
        this.LJI = 0;
        this.LJIIIZ = 0;
        this.LJIIJJI = false;
        this.LJIIL = false;
        this.LJIILJJIL = new DuetContext((byte) 0);
        this.LJIJI = true;
        this.LJIJJ = true;
        this.LJJIII = -1.0f;
        this.LJJIIZI = 0;
        this.LJJIJIIJI = false;
        this.LJJIJIIJIL = new RecordContext();
        this.LJJIJIL = false;
        this.LIZ = i;
        this.LJJIIZ = str;
        this.LJJIIZI = i2;
    }
}
