package com.bytedance.android.live.liveinteract.linkroom;

import X.2Pr;
import X.7ju;
import X.AnonymousClass0S6;
import X.AnonymousClass0UT;
import X.AnonymousClass1PF;
import X.AnonymousClass1WJ;
import X.AnonymousClass1YT;
import X.AnonymousClass2BM;
import X.AnonymousClass2BN;
import X.AnonymousClass2BO;
import X.AnonymousClass2BP;
import X.C11100cm;
import X.C14250hr;
import X.C14350i1;
import X.C14600iQ;
import X.C14620iS;
import X.C14650iV;
import X.C14740ie;
import X.C14810il;
import X.C16200l0;
import X.C16590ld;
import X.C16600le;
import X.C16630lh;
import X.C18230oH;
import X.C18270oL;
import X.C18470of;
import X.C20070rF;
import X.C20260rY;
import X.C21140sy;
import X.C24070xh;
import X.C24120xm;
import X.C24150xp;
import X.C24440yI;
import X.C24460yK;
import X.C31851Ol;
import X.C31861Om;
import X.C32491Qx;
import X.C32501Qy;
import X.C32691Rr;
import X.C33351Uf;
import X.C33431Un;
import X.C33641Vi;
import X.C35681bK;
import X.C41491kh;
import X.D2a;
import X.GiY;
import X.Gyq;
import X.H7I;
import X.HEP;
import X.Ls0;
import X.Ls2;
import X.M12;
import android.view.SurfaceView;
import com.bytedance.android.live.base.model.user.User;
import com.bytedance.android.live.liveinteract.api.IInteractService;
import com.bytedance.android.live.liveinteract.linkroom.widget.AudienceBottomLeftLinkWidget;
import com.bytedance.android.live.microom.IMicRoomService;
import com.bytedance.android.live.publicscreen.api.IPublicScreenService;
import com.bytedance.android.livesdk.chatroom.model.interact.LinkPlayerInfo;
import com.bytedance.android.livesdk.chatroom.model.sociallive.SocialLinkPlayerInfo;
import com.bytedance.android.livesdk.model.message.TeamUsersInfo;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.android.livesdkapi.depend.model.live.RoomLinkInfo;
import com.bytedance.android.livesdkapi.depend.model.live.StreamUrl;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannelGlobal;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import kotlin.h.b.n;

public class InteractService implements IInteractService {
    public boolean mHasAddInteractObserve;
    public final D2a<Integer> mInteractObserver = new C32491Qx(this);
    public final List<Gyq> mListeners = new ArrayList();

    static {
        Covode.recordClassIndex(7037);
    }

    public Class<AudienceBottomLeftLinkWidget> getBottomLeftLinkHostWidget() {
        return AudienceBottomLeftLinkWidget.class;
    }

    public String getLinkStatus4H5() {
        return C16200l0.LIZ;
    }

    public Set<Long> getSocialLocalInviteUIDs() {
        return C14810il.LIZ;
    }

    public C14620iS createCommonLinkMicFeedViewManager() {
        return new C35681bK();
    }

    public long getBattleId() {
        return C16590ld.LIZ.LJ();
    }

    public SurfaceView getLinkInAnchorSurface() {
        return GiY.LIZ().LJJ;
    }

    public C14740ie getLinkWidgetFactory() {
        return new C32691Rr();
    }

    public int getLinkedGuestNum() {
        return GiY.LIZ().LJJIFFI;
    }

    public int getMultiGuestOnlineGuestsViews() {
        return GiY.LIZ().LJIJJLI;
    }

    public List<TeamUsersInfo> getTeamInfo() {
        return C16590ld.LIZ.LJIIJJI;
    }

    public boolean isBattleStarter() {
        return C16590ld.LIZ.LIZLLL;
    }

    public boolean isInRandomLinkMic() {
        return AnonymousClass1PF.LIZ();
    }

    public boolean isNotInLinkMicProgress() {
        return C21140sy.LIZIZ();
    }

    private final void addInteractObserve() {
        C31861Om.LIZ().LIZ(this.mInteractObserver);
        this.mHasAddInteractObserve = true;
    }

    public String getCurrentInviteeList() {
        return C24120xm.LIZ(C31851Ol.LLFII.LIZ().LJIILL);
    }

    public int getCurrentLinkMode() {
        return C31851Ol.LLFII.LIZ().LIZ();
    }

    public int getMaxLinkNum() {
        return C20260rY.LIZJ.LIZ().LJIIIZ();
    }

    public long getRivalAnchorUidWhenAnchorLinkMic() {
        return C31851Ol.LLFII.LIZ().LJFF;
    }

    public Set<Long> getUninvitedUidSet() {
        Set<Long> set = GiY.LIZ().LJJI;
        n.LIZIZ(set, "");
        return set;
    }

    public boolean hasMultiCoHostPermission() {
        return C18470of.LIZIZ().isMultiCoHost();
    }

    public boolean isAudienceApplied() {
        GiY LIZ = GiY.LIZ();
        n.LIZIZ(LIZ, "");
        return LIZ.LIZLLL;
    }

    public boolean isBattling() {
        if (C16630lh.START == C16590ld.LIZ.LIZJ()) {
            return true;
        }
        return false;
    }

    public boolean isInCoHost() {
        return C31851Ol.LLFII.LIZ().LIZ;
    }

    public boolean isInMultiGuest() {
        GiY LIZ = GiY.LIZ();
        n.LIZIZ(LIZ, "");
        return LIZ.LIZLLL;
    }

    public boolean isMultiGuestV3() {
        return C20260rY.LIZJ.LIZ().LIZLLL();
    }

    public void preloadAnchorViewHolder() {
        H7I.LJFF.LIZ(2131561984, 5, 0);
    }

    public boolean canLinkMic() {
        if ((isLinkingMic() || isInRandomLinkMic()) && !checkMultiCoHostStatus()) {
            return false;
        }
        return true;
    }

    public void disconnectMultiGuestV3() {
        Ls2<2Pr> LIZIZ;
        C20070rF LIZ = AnonymousClass1WJ.LJFF.LIZ();
        if (LIZ != null && (LIZIZ = LIZ.LIZIZ()) != null) {
            LIZIZ.invoke();
        }
    }

    public String getCurrentPkState() {
        if (C16590ld.LIZ.LIZJ() == C16630lh.START) {
            return "in_pk";
        }
        if (C16590ld.LIZ.LIZJ() == C16630lh.PUNISH) {
            return "pk_punish";
        }
        return "";
    }

    public Set<Long> getHasInvitedUidSet() {
        if (C20260rY.LIZJ.LIZ().LIZLLL()) {
            return C14250hr.LIZIZ().getHasInvitedUidSet();
        }
        return C33351Uf.LIZLLL;
    }

    public String getInviteeList() {
        if (!isInCoHost()) {
            return "";
        }
        return C24120xm.LIZ(C31851Ol.LLFII.LIZ().LJIILL);
    }

    public C24070xh getLinkCrossRoomSeiData() {
        Object LIZ = C41491kh.LIZ.LIZ("LINK_CROSS_DATA_HOLDER");
        if (LIZ == null || !(LIZ instanceof C31851Ol)) {
            return null;
        }
        return ((C31851Ol) LIZ).LJLJL;
    }

    public int getMatchPreviewProgressStatus() {
        C16600le r5 = C16590ld.LIZ;
        if (!r5.LJJIJIIJI) {
            return -1;
        }
        if (((double) r5.LJJIIZI) > 0.5d || ((double) r5.LJJIJ) <= 0.5d) {
            return 0;
        }
        return 1;
    }

    public int getMatchProgressStatus() {
        C16600le r2 = C16590ld.LIZ;
        if (r2.LIZJ() != C16630lh.START) {
            return -1;
        }
        if (((double) r2.LJJIIZI) > 0.5d) {
            return 1;
        }
        return 0;
    }

    public void handleLiveRoomStopped() {
        if (GiY.LIZ().LJJIFFI > 0) {
            C24150xp.LIZLLL("live_over");
        }
        C24440yI.LIZ.LIZ();
    }

    public boolean isAnchorVideoEnable() {
        Object LIZ = C41491kh.LIZ.LIZ("MULTI_GUEST_DATA_HOLDER");
        if (LIZ == null) {
            return true;
        }
        if (!(LIZ instanceof C33641Vi) || !((C33641Vi) LIZ).LJFF) {
            return false;
        }
        return true;
    }

    public boolean isIn1VN() {
        Object LIZ = C41491kh.LIZ.LIZ("MULTI_GUEST_DATA_HOLDER");
        if (!(LIZ instanceof C33641Vi) || ((C33641Vi) LIZ).LJJ == C14600iQ.ONE_TO_N) {
            return false;
        }
        return true;
    }

    public boolean isInteracting() {
        C31861Om LIZ = C31861Om.LIZ();
        n.LIZIZ(LIZ, "");
        Integer num = (Integer) LIZ.LJIILIIL;
        n.LIZIZ(num, "");
        int intValue = num.intValue();
        if (intValue == 2 || intValue == 1) {
            return true;
        }
        return false;
    }

    public boolean isLinkingMic() {
        GiY LIZ = GiY.LIZ();
        n.LIZIZ(LIZ, "");
        if (LIZ.LIZLLL || C31851Ol.LLFII.LIZ().LIZ) {
            return true;
        }
        return false;
    }

    public boolean isMultiLiveFixLayout() {
        Object LIZ = C41491kh.LIZ.LIZ("MULTI_GUEST_DATA_HOLDER");
        if (!(LIZ instanceof C33641Vi)) {
            return false;
        }
        C33641Vi r2 = (C33641Vi) LIZ;
        if (r2.LJJ == C14600iQ.GRID_FIX || r2.LJJ == C14600iQ.FLOATING_FIX) {
            return true;
        }
        return false;
    }

    public boolean isMultiLiveFloatLayout() {
        Object LIZ = C41491kh.LIZ.LIZ("MULTI_GUEST_DATA_HOLDER");
        if (!(LIZ instanceof C33641Vi)) {
            return false;
        }
        C33641Vi r2 = (C33641Vi) LIZ;
        if (r2.LJJ == C14600iQ.FLOATING_FIX || r2.LJJ == C14600iQ.FLOATING) {
            return true;
        }
        return false;
    }

    public boolean isMultiLiveGridLayout() {
        Object LIZ = C41491kh.LIZ.LIZ("MULTI_GUEST_DATA_HOLDER");
        if (!(LIZ instanceof C33641Vi)) {
            return false;
        }
        C33641Vi r2 = (C33641Vi) LIZ;
        if (r2.LJJ == C14600iQ.GRID_FIX || r2.LJJ == C14600iQ.GRID) {
            return true;
        }
        return false;
    }

    public boolean isMultiLiveLayout() {
        Object LIZ = C41491kh.LIZ.LIZ("MULTI_GUEST_DATA_HOLDER");
        if (!(LIZ instanceof C33641Vi) || ((C33641Vi) LIZ).LJJ == C14600iQ.NORMAL) {
            return false;
        }
        return true;
    }

    public boolean isRoomInBattle() {
        C16630lh LIZJ = C16590ld.LIZ.LIZJ();
        if (LIZJ.compareTo(C16630lh.START) < 0 || LIZJ.compareTo(C16630lh.END) >= 0) {
            return false;
        }
        return true;
    }

    public void onInit() {
        ((IPublicScreenService) C11100cm.LIZ(IPublicScreenService.class)).addOnRegistryReadyListener(new C32501Qy());
    }

    public void preloadWidgetView() {
        AnonymousClass0S6.LJFF.LIZ(2131562102);
        AnonymousClass0S6.LJFF.LIZ(2131562101);
        AnonymousClass0S6.LJFF.LIZ(2131562088);
    }

    public long getChannelId() {
        Room room;
        if (C14350i1.LIZ(getCurrentLinkMode(), 4)) {
            return C31851Ol.LLFII.LIZ().LJ;
        }
        if (!C14350i1.LIZ(getCurrentLinkMode(), 2) || (room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class)) == null) {
            return 0;
        }
        return room.getId();
    }

    public String getConnectionType() {
        if (isRoomInBattle()) {
            return "manual_pk";
        }
        if (isInCoHost()) {
            return "anchor";
        }
        GiY LIZ = GiY.LIZ();
        n.LIZIZ(LIZ, "");
        if (LIZ.LJI) {
            return "audience";
        }
        return "normal";
    }

    public List<Long> getMultiCoHostLinkedUserList() {
        List<C18230oH> coHostLinkedUserList = C14250hr.LIZJ().getCoHostLinkedUserList();
        ArrayList arrayList = new ArrayList();
        for (C18230oH r0 : coHostLinkedUserList) {
            if (r0 != null) {
                arrayList.add(Long.valueOf(r0.LJIILIIL));
            }
        }
        return arrayList;
    }

    public String getRoomScene() {
        C24460yK r0;
        if (((IMicRoomService) C11100cm.LIZ(IMicRoomService.class)).isMicRoomForCurrentRoom()) {
            r0 = C24460yK.LINE_UP;
        } else {
            AnonymousClass0UT LIZ = C11100cm.LIZ(IInteractService.class);
            Objects.requireNonNull(LIZ, "null cannot be cast to non-null type com.bytedance.android.live.liveinteract.api.IInteractService");
            IInteractService iInteractService = (IInteractService) LIZ;
            if (iInteractService.isBattling()) {
                r0 = C24460yK.LINK_MIC_PK;
            } else if (iInteractService.getLinkedGuestNum() > 0) {
                r0 = C24460yK.LINK_MIC_GUEST;
            } else if (iInteractService.isInCoHost()) {
                r0 = C24460yK.LINK_MIC_ANCHOR;
            } else {
                r0 = C24460yK.NORMAL_VIDEO;
            }
        }
        return r0.getDesc();
    }

    public Set<Long> getSocialOnlineUserIds() {
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        for (SocialLinkPlayerInfo socialLinkPlayerInfo : C14810il.LIZIZ.LIZ) {
            User user = socialLinkPlayerInfo.LIZ;
            n.LIZIZ(user, "");
            linkedHashSet.add(Long.valueOf(user.getId()));
        }
        return linkedHashSet;
    }

    public boolean isAdjustParentForPreviewDialog() {
        C31861Om LIZ = C31861Om.LIZ();
        n.LIZIZ(LIZ, "");
        if (LIZ.LIZJ()) {
            return true;
        }
        Object LIZ2 = C41491kh.LIZ.LIZ("MULTI_GUEST_DATA_HOLDER");
        if (!(LIZ2 instanceof C33641Vi)) {
            LIZ2 = null;
        }
        C33641Vi r2 = (C33641Vi) LIZ2;
        if (r2 == null) {
            return false;
        }
        if (r2.LJJIIJ || r2.LJJIIJZLJL) {
            return true;
        }
        return false;
    }

    private final boolean checkMultiCoHostStatus() {
        if (!hasMultiCoHostPermission()) {
            return false;
        }
        List<C18230oH> coHostUserList = C14250hr.LIZJ().getCoHostUserList();
        ArrayList arrayList = new ArrayList();
        for (T next : coHostUserList) {
            C18230oH r2 = (C18230oH) next;
            if (r2.LJFF == C18270oL.INVITING || (r2.LJFF == C18270oL.INVITED && r2.LIZJ())) {
                arrayList.add(next);
            }
        }
        int size = arrayList.size();
        int size2 = C14250hr.LIZJ().getCoHostUserList().size();
        if (size < 3 && size2 < 4) {
            return true;
        }
        return false;
    }

    public Set<Long> getSocialInvitingUserId() {
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        List<SocialLinkPlayerInfo> list = C14810il.LIZIZ.LIZJ;
        ArrayList<SocialLinkPlayerInfo> arrayList = new ArrayList<>();
        for (T next : list) {
            if (((SocialLinkPlayerInfo) next).LIZLLL == 3) {
                arrayList.add(next);
            }
        }
        for (SocialLinkPlayerInfo socialLinkPlayerInfo : arrayList) {
            User user = socialLinkPlayerInfo.LIZ;
            n.LIZIZ(user, "");
            linkedHashSet.add(Long.valueOf(user.getId()));
        }
        return linkedHashSet;
    }

    public Set<Long> getSocialOnlineAndWaitingUserId() {
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        for (SocialLinkPlayerInfo socialLinkPlayerInfo : C14810il.LIZIZ.LIZ) {
            User user = socialLinkPlayerInfo.LIZ;
            n.LIZIZ(user, "");
            linkedHashSet.add(Long.valueOf(user.getId()));
        }
        for (SocialLinkPlayerInfo socialLinkPlayerInfo2 : C14810il.LIZIZ.LIZIZ) {
            User user2 = socialLinkPlayerInfo2.LIZ;
            n.LIZIZ(user2, "");
            linkedHashSet.add(Long.valueOf(user2.getId()));
        }
        return linkedHashSet;
    }

    public String getDebugInfo() {
        String str;
        Long l;
        String str2;
        Long l2;
        StreamUrl streamUrl;
        RoomLinkInfo linkMicInfo;
        List list;
        RoomLinkInfo linkMicInfo2;
        Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
        StringBuilder sb = new StringBuilder();
        StringBuilder sb2 = new StringBuilder("LinkMic State：");
        String str3 = "none";
        if (isRoomInBattle()) {
            str = "co-host pk";
        } else if (isInCoHost()) {
            str = "co-host";
        } else if (isInMultiGuest()) {
            str = "multi-guest";
        } else {
            GiY LIZ = GiY.LIZ();
            n.LIZIZ(LIZ, "");
            if (LIZ.LJI) {
                str = "multi-guest audience";
            } else {
                str = str3;
            }
        }
        sb2.append(str);
        sb2.append(10);
        sb.append(sb2.toString());
        StringBuilder sb3 = new StringBuilder("MultiLiveType：");
        String str4 = null;
        if (room == null || (linkMicInfo2 = room.getLinkMicInfo()) == null) {
            l = null;
        } else {
            l = Long.valueOf(linkMicInfo2.LJFF);
        }
        sb3.append(l);
        sb3.append(" (0:none or multi_guest_v1 / 1:multi_live or 1vn)\n");
        sb.append(sb3.toString());
        StringBuilder sb4 = new StringBuilder("AudienceIdList：");
        if (room == null || (linkMicInfo = room.getLinkMicInfo()) == null || (list = linkMicInfo.LIZLLL) == null) {
            str2 = null;
        } else {
            str2 = list.toString();
        }
        sb4.append(str2);
        sb4.append(10);
        sb.append(sb4.toString());
        StringBuilder sb5 = new StringBuilder("Stream ID：");
        if (room != null) {
            l2 = Long.valueOf(room.getStreamId());
        } else {
            l2 = null;
        }
        sb5.append(l2);
        sb5.append(10);
        sb.append(sb5.toString());
        StringBuilder sb6 = new StringBuilder("Stream Url：");
        if (!(room == null || (streamUrl = room.getStreamUrl()) == null)) {
            str4 = streamUrl.LJFF;
        }
        sb6.append(str4);
        sb6.append(10);
        sb.append(sb6.toString());
        StringBuilder sb7 = new StringBuilder("Recent SEI：");
        if (isInCoHost()) {
            str3 = C31851Ol.LLFII.LIZ().LJIL;
        } else if (isInMultiGuest()) {
            str3 = GiY.LIZ().LJFF;
        } else {
            GiY LIZ2 = GiY.LIZ();
            n.LIZIZ(LIZ2, "");
            if (LIZ2.LJI) {
                str3 = GiY.LIZ().LJFF;
            }
        }
        sb7.append(str3);
        sb7.append(10);
        sb.append(sb7.toString());
        String sb8 = sb.toString();
        n.LIZIZ(sb8, "");
        return sb8;
    }

    public void removeInteractStateChangeListener(Gyq gyq) {
        List<Gyq> list = this.mListeners;
        Objects.requireNonNull(list, "null cannot be cast to non-null type kotlin.collections.MutableCollection<T>");
        Ls0.LIZIZ(list).remove(gyq);
    }

    public void registerInteractStateChangeListener(Gyq gyq) {
        if (!this.mHasAddInteractObserve) {
            addInteractObserve();
        }
        if (gyq != null && !this.mListeners.contains(gyq)) {
            this.mListeners.add(gyq);
        }
    }

    public C14650iV getUserRole(long j) {
        Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
        if (room == null) {
            return C14650iV.NORMAL_AUDIENCE;
        }
        if (j == room.getOwnerUserId()) {
            return C14650iV.CURRENT_ANCHOR;
        }
        if (j == C31851Ol.LLFII.LIZ().LJFF) {
            return C14650iV.GUEST_ANCHOR;
        }
        if (7ju.LIZ.LIZ.containsKey(Long.valueOf(j))) {
            return C14650iV.GUEST_AUDIENCE;
        }
        return C14650iV.NORMAL_AUDIENCE;
    }

    public int getLinkState(User user) {
        M12.LIZ(user);
        Object LIZ = C41491kh.LIZ.LIZ("LINK_USER_INFO_CENTER");
        if (!(LIZ instanceof C33431Un)) {
            LIZ = null;
        }
        C33431Un r1 = (C33431Un) LIZ;
        if (r1 != null) {
            M12.LIZ(user);
            for (LinkPlayerInfo linkPlayerInfo : r1.LIZIZ) {
                User user2 = linkPlayerInfo.LIZIZ;
                n.LIZIZ(user2, "");
                if (user2.getId() == user.getId()) {
                    return linkPlayerInfo.LIZLLL;
                }
            }
        }
        return 0;
    }

    public AnonymousClass1YT createMultiLiveFeedView(int i, long j, long j2, boolean z) {
        long j3 = j2;
        boolean z2 = z;
        long j4 = j;
        switch (i) {
            case 11:
                return new AnonymousClass2BM(j4, j3, z2);
            case 12:
                return new AnonymousClass2BN(j4, j3, z2);
            case 13:
                return new AnonymousClass2BO(j4, j3, z2);
            case 14:
                return new AnonymousClass2BP(j4, j3, z2);
            default:
                return null;
        }
    }
}
