package com.ss.android.ugc.aweme.im.sdk.chat.data.model;

import X.070;
import X.0HH;
import X.2HN;
import X.3Mp;
import X.9EH;
import X.AuX;
import X.C1001Ib2;
import X.C1415Ihi;
import X.C1416Ihj;
import X.LeS;
import X.Lea;
import X.Ltt;
import X.M12;
import X.NuT;
import X.NuV;
import X.Qx3;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import com.bytedance.covode.number.Covode;
import com.google.gson.a.c;
import com.ss.android.ugc.aweme.im.sdk.chat.data.model.SystemContent;
import com.ss.android.ugc.aweme.im.service.model.IMUser;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import kotlin.h.b.n;
import kotlin.o.z;

public final class GroupSystemContent extends SystemContent {
    public static final Companion Companion = new Companion((2HN) null);
    public static final Typeface tf = NuT.LIZ().LIZ(NuV.LJI);
    @c(LIZ = "group_name")
    public String groupName;
    @c(LIZ = "max_display_object_users")
    public int maxObjectUsers;
    @c(LIZ = "max_display_subject_users")
    public int maxSubjectUsers;
    @c(LIZ = "object_users")
    public List<? extends IMUser> objectUsers;
    @c(LIZ = "subject_users")
    public List<? extends IMUser> subjectUsers;

    public static final class Companion {
        static {
            Covode.recordClassIndex(84098);
        }

        public Companion() {
        }

        public /* synthetic */ Companion(2HN r1) {
            this();
        }
    }

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

    public final int getMaxObjectUsers() {
        return this.maxObjectUsers;
    }

    public final int getMaxSubjectUsers() {
        return this.maxSubjectUsers;
    }

    public final List<IMUser> getObjectUsers() {
        return this.objectUsers;
    }

    public final List<IMUser> getSubjectUsers() {
        return this.subjectUsers;
    }

    public final String getMsgHint() {
        String spannableStringBuilder = getNoticeText(false).toString();
        n.LIZIZ(spannableStringBuilder, "");
        return spannableStringBuilder;
    }

    static {
        Covode.recordClassIndex(84097);
    }

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

    public final void setMaxObjectUsers(int i) {
        this.maxObjectUsers = i;
    }

    public final void setMaxSubjectUsers(int i) {
        this.maxSubjectUsers = i;
    }

    public final void setObjectUsers(List<? extends IMUser> list) {
        this.objectUsers = list;
    }

    public final void setSubjectUsers(List<? extends IMUser> list) {
        this.subjectUsers = list;
    }

    public final SpannableStringBuilder getNoticeText(boolean z) {
        IMUser iMUser;
        String str = "";
        switch (this.type) {
            case 103101:
                return formatTips$default(this, 2131825571, getSystemUsersSpans(this.subjectUsers, 1, z), new String[]{"[[0]]"}, (SpannableStringBuilder) null, 8, (Object) null);
            case 103102:
                return formatTips(2131825580, getSystemUsersSpans(this.subjectUsers, 1, z), new String[]{"[[0]]", "[[1]]"}, getSystemUsersSpans(this.objectUsers, 1, z));
            case 103103:
                return formatTips$default(this, 2131825581, getSystemUsersSpans(this.subjectUsers, 1, z), new String[]{"[[0]]"}, (SpannableStringBuilder) null, 8, (Object) null);
            case 103104:
                return formatTips$default(this, 2131825583, getSystemUsersSpans(this.subjectUsers, 1, z), new String[]{"[[0]]"}, (SpannableStringBuilder) null, 8, (Object) null);
            case 103105:
                return formatTips(2131825572, getSystemUsersSpans(this.subjectUsers, 1, z), new String[]{"[[0]]", "[[1]]"}, getSystemUsersSpans(this.objectUsers, this.maxObjectUsers, z));
            case 103106:
                SpannableStringBuilder systemUsersSpans = getSystemUsersSpans(this.subjectUsers, 1, z);
                String[] strArr = new String[2];
                strArr[0] = "[[0]]";
                String str2 = this.groupName;
                if (str2 != null) {
                    str = str2;
                }
                strArr[1] = str;
                return formatTips$default(this, 2131825579, systemUsersSpans, strArr, (SpannableStringBuilder) null, 8, (Object) null);
            case 103107:
                List<? extends IMUser> list = this.subjectUsers;
                if (list == null || (iMUser = (IMUser) Lea.LJIIIIZZ(list)) == null || !(!n.LIZ(iMUser.getUid(), 3Mp.LIZIZ()))) {
                    return new SpannableStringBuilder(9EH.LJJIFFI.LIZ().getString(2131825578));
                }
                return new SpannableStringBuilder(9EH.LJJIFFI.LIZ().getString(2131825577, new Object[]{iMUser.getDisplayName()}));
            case 103108:
                return new SpannableStringBuilder(9EH.LJJIFFI.LIZ().getString(2131825628));
            case 103109:
                String string = 9EH.LJJIFFI.LIZ().getString(2131825627);
                n.LIZIZ(string, str);
                String string2 = 9EH.LJJIFFI.LIZ().getString(2131825626);
                n.LIZIZ(string2, str);
                String LIZ = 0HH.LIZ(string, Arrays.copyOf(new Object[]{string2}, 1));
                n.LIZIZ(LIZ, str);
                SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(LIZ);
                int length = string.length() - 3;
                int length2 = LIZ.length() - 1;
                spannableStringBuilder.setSpan(new GroupSystemContent$getNoticeText$customClickableSpan$1(), length, length2, 18);
                spannableStringBuilder.setSpan(new Ltt(53, false), length, length2, 18);
                spannableStringBuilder.setSpan(new ForegroundColorSpan(9EH.LJJIFFI.LIZ().getResources().getColor(2131099722)), length, length2, 18);
                return spannableStringBuilder;
            default:
                return new SpannableStringBuilder(9EH.LJJIFFI.LIZ().getString(2131825616));
        }
    }

    /* JADX WARNING: type inference failed for: r12v0 */
    /* JADX WARNING: type inference failed for: r12v1, types: [boolean] */
    /* JADX WARNING: type inference failed for: r12v2 */
    private final SpannableStringBuilder getSystemUsersSpans(List<? extends IMUser> list, int i, boolean z) {
        String str;
        int i2 = i;
        if (i2 <= 0) {
            i2 = 1;
        }
        int LIZJ = 070.LIZJ(9EH.LJJIFFI.LIZ(), 2131099757);
        List<IMUser> LIZ = C1001Ib2.LIZIZ.LIZ().LIZ(list);
        AuX auX = new AuX();
        int LIZLLL = Qx3.LIZLLL(LIZ.size(), i2);
        if (LIZ.size() - i2 == 1 && LIZ.size() >= 2) {
            LIZLLL = LIZ.size() - 2;
        }
        ? r12 = 0;
        List<IMUser> subList = LIZ.subList(0, LIZLLL);
        Iterator<T> it = subList.iterator();
        int i3 = 0;
        while (true) {
            str = "";
            if (!it.hasNext()) {
                break;
            }
            IMUser next = it.next();
            int i4 = i3 + 1;
            if (i3 < 0) {
                LeS.LIZIZ();
            }
            IMUser iMUser = next;
            String displayName = iMUser.getDisplayName();
            if (!((displayName == null || displayName.length() == 0) && (displayName = iMUser.getUid()) == null)) {
                str = displayName;
            }
            if (z) {
                C1415Ihi LIZ2 = C1416Ihj.LIZ(LIZJ, iMUser.getUid(), iMUser.getSecUid(), r12);
                SystemContent.Key key = new SystemContent.Key();
                key.action = 9;
                LIZ2.LIZ = key;
                Object[] objArr = new Object[2];
                objArr[r12] = new Ltt(62);
                objArr[1] = LIZ2;
                List<Object> LIZIZ = LeS.LIZIZ(objArr);
                M12.LIZ(str, LIZIZ);
                int length = auX.LIZ.length();
                auX.LIZIZ.LIZ(auX.LIZ, str);
                int length2 = auX.LIZ.length();
                for (Object span : LIZIZ) {
                    auX.LIZ.setSpan(span, length, length2, 33);
                }
            } else {
                auX.LIZIZ(str);
            }
            if (i3 != subList.size() - 1) {
                auX.LIZ(9EH.LJJIFFI.LIZ().getString(2131823888) + ' ');
            }
            i3 = i4;
            r12 = 0;
        }
        if (LIZ.size() <= LIZLLL) {
            return auX.LIZ;
        }
        String string = 9EH.LJJIFFI.LIZ().getResources().getString(2131825617, new Object[]{"{{%s}}", String.valueOf(LIZ.size() - LIZLLL)});
        n.LIZIZ(string, str);
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
        spannableStringBuilder.append(string);
        int LIZ3 = z.LIZ(spannableStringBuilder, "{{%s}}", 0, false, 6);
        SpannableStringBuilder replace = spannableStringBuilder.replace(LIZ3, LIZ3 + 6, auX.LIZ);
        n.LIZIZ(replace, str);
        return replace;
    }

    private final SpannableStringBuilder formatTips(int i, SpannableStringBuilder spannableStringBuilder, String[] strArr, SpannableStringBuilder spannableStringBuilder2) {
        SpannableStringBuilder spannableStringBuilder3 = new SpannableStringBuilder();
        try {
            spannableStringBuilder3.append(9EH.LJJIFFI.LIZ().getString(i, Arrays.copyOf(strArr, strArr.length)));
            int LIZ = z.LIZ(spannableStringBuilder3, "[[0]]", 0, false, 6);
            spannableStringBuilder3.replace(LIZ, LIZ + 5, spannableStringBuilder);
            if (spannableStringBuilder2 != null) {
                int LIZ2 = z.LIZ(spannableStringBuilder3, "[[1]]", 0, false, 6);
                spannableStringBuilder3.replace(LIZ2, LIZ2 + 5, spannableStringBuilder2);
            }
        } catch (Exception e) {
            0HH.LIZ(e);
        }
        return spannableStringBuilder3;
    }

    public static /* synthetic */ SpannableStringBuilder getSystemUsersSpans$default(GroupSystemContent groupSystemContent, List list, int i, boolean z, int i2, Object obj) {
        if ((i2 & 4) != 0) {
            z = false;
        }
        return groupSystemContent.getSystemUsersSpans(list, i, z);
    }

    public static /* synthetic */ SpannableStringBuilder formatTips$default(GroupSystemContent groupSystemContent, int i, SpannableStringBuilder spannableStringBuilder, String[] strArr, SpannableStringBuilder spannableStringBuilder2, int i2, Object obj) {
        if ((i2 & 8) != 0) {
            spannableStringBuilder2 = null;
        }
        return groupSystemContent.formatTips(i, spannableStringBuilder, strArr, spannableStringBuilder2);
    }
}
