package com.videogo.ui.common;

import com.videogo.global.GlobalKit;
import com.videogo.openapi.EZOpenSDK;
import com.videogo.openapi.EZPlayer;
import com.videogo.openapi.EzvizAPI;
import com.videogo.stream.EZDeviceStreamDownload;

/**
 * Copyright (C) 2026 HIKVISION Inc.
 * Comments:取流特殊配置加载
 *
 * @author ChengJun9
 * @date 2026/3/5 10:36
 */
public class EZStreamConfigLoader {

    /**
     * 加载预览特殊配置，startRealPlay之前设置
     *
     * @param realPlayPlayer 预览播放器
     */
    public static void loadRealPlaySpecialConfigToPlayer(EZPlayer realPlayPlayer) {
        // 国内 & 小权限token模式下，设置自己服务器生成的tkToken
        if (!EzvizAPI.getInstance().isUsingGlobalSDK() && EZOpenSDK.isEnableSDKWithTKToken()) {
            realPlayPlayer.setStreamToken(GlobalKit.getInstance().previewStreamToken);
        }
        // 播放器禁用P2P
        if (GlobalKit.getInstance().isPlayerP2PDisable) {
            realPlayPlayer.setPlayerDisableP2P();
        }
        // 取流前要切换清晰度，会增加出画面的耗时；一般不用设置，如果业务需要选择设置
        realPlayPlayer.setVideoQuality(GlobalKit.getInstance().videoQuality);
    }

    /**
     * 加载SD卡回放特殊配置，startPlayback之前设置
     *
     * @param playbackPlayer 回放播放器
     */
    public static void loadPlaybackSpecialConfigToPlayer(EZPlayer playbackPlayer) {
        // 国内 & 小权限token模式下，设置自己服务器生成的tkToken
        if (!EzvizAPI.getInstance().isUsingGlobalSDK() && EZOpenSDK.isEnableSDKWithTKToken()) {
            playbackPlayer.setStreamToken(GlobalKit.getInstance().playbackStreamToken);
        }
        // 播放器禁用P2P
        if (GlobalKit.getInstance().isPlayerP2PDisable) {
            playbackPlayer.setPlayerDisableP2P();
        }
        // 纯音频播放
        if (GlobalKit.getInstance().enablePureAudio) {
            playbackPlayer.enablePureAudio();
        }
    }

    /**
     * 加载对讲特殊配置，startVoiceTalk之前设置
     *
     * @param voiceTalkPlayer 对讲播放器
     */
    public static void loadVoicetalkSpecialConfigToPlayer(EZPlayer voiceTalkPlayer) {
        // 国内 & 小权限token模式下，设置自己服务器生成的tkToken
        if (!EzvizAPI.getInstance().isUsingGlobalSDK() && EZOpenSDK.isEnableSDKWithTKToken()) {
            voiceTalkPlayer.setStreamToken(GlobalKit.getInstance().talkStreamToken);
        }
    }

    /**
     * 加载SD卡下载特殊配置
     *
     * @param deviceStreamDownloader 下载器
     */
    public static void loadDownloadDeviceVideoSpecialConfigToStreamDownload(EZDeviceStreamDownload deviceStreamDownloader) {
        // 国内平台 && 使用小权限token模式的时候，需要设置小权限token
        if (!EzvizAPI.getInstance().isUsingGlobalSDK() && EZOpenSDK.isEnableSDKWithTKToken()) {
            deviceStreamDownloader.setStreamToken(GlobalKit.getInstance().playbackStreamToken);
        }
    }
}
