package com.cr.common

import dji.v5.common.video.channel.VideoChannelType
import dji.v5.manager.datacenter.livestream.StreamQuality

/**
 * 操作系统：MAC系统
 * 创建者：王成
 * 创建日期：2023/9/12 15:11
 * 描述：直播管理器 该类与DJI高度相关
 */
class CrLiveManager {

    // define: 2023/9/12 质量列表
    private var qualityList:MutableList<String> = mutableListOf()

    /**
     * 单例必备
     */
    object InstanceHelper{
        var self = CrLiveManager()
    }

    companion object{
        /**
         * 获取单例
         * @return CrLiveManager
         */
        fun getInstance() = InstanceHelper.self
    }

    /**
     * 获取直播视频质量的描述信息
     * @param streamQuality StreamQuality
     * @return String
     */
    fun getQualityTitle(streamQuality:StreamQuality):String{
        return when(streamQuality){
            StreamQuality.SD->{
                "标清(960*540)"
            }
            StreamQuality.HD->{
                "高清(1280*720)"
            }
            StreamQuality.FULL_HD->{
                "超高清(1920*1080)"
            }
            StreamQuality.UNKNOWN->{
                "未知"
            }
        }
    }

    /**
     * 根据视频质量获取视频的分辨率
     * @param streamQuality StreamQuality
     * @return List<Int>
     */
    fun getQualityToVideoResolution(streamQuality:StreamQuality):List<Int>{
        return when(streamQuality){
            StreamQuality.SD->{
                mutableListOf(960,540)
            }
            StreamQuality.HD->{
                mutableListOf(1280,720)
            }
            StreamQuality.FULL_HD->{
                mutableListOf(1920,1080)
            }
            StreamQuality.UNKNOWN->{
                mutableListOf(0,0)
            }
        }
    }

    /**
     * 根据直播视频质量描述获取视频质量
     * @param titleQuality String
     * @return StreamQuality
     */
    fun getQuality(titleQuality:String):StreamQuality{
        return when(titleQuality){
            "标清(960*540)"->{
                StreamQuality.SD
            }
            "高清(1280*720)"->{
                StreamQuality.HD
            }
            "超高清(1920*1080)"->{
                StreamQuality.FULL_HD
            }
            else->
                StreamQuality.UNKNOWN
        }
    }

    /**
     * 获取码流通道描述获取码流通道
     * @param videoChannelType VideoChannelType
     * @return String
     */
    fun getChannelTypeTitle(videoChannelType: VideoChannelType):String{
        return when(videoChannelType){
            VideoChannelType.PRIMARY_STREAM_CHANNEL->{
                "主码流通道"
            }
            VideoChannelType.SECONDARY_STREAM_CHANNEL->{
                "副码流通道"
            }
            VideoChannelType.EXTENDED_STREAM_CHANNEL->{
                "扩展码流通道"
            }
            else->{
                "主码流通道"
            }
        }
    }

    /**
     * 根据码流描述获取视频通道
     * @param titleChannelType String
     * @return VideoChannelType
     */
    fun getChannelType(titleChannelType:String):VideoChannelType{
        return when(titleChannelType){
            "主码流通道"->{
                VideoChannelType.PRIMARY_STREAM_CHANNEL
            }
            "副码流通道"->{
                VideoChannelType.SECONDARY_STREAM_CHANNEL
            }
            "扩展码流通道"->{
                VideoChannelType.EXTENDED_STREAM_CHANNEL
            }
            else -> {
                VideoChannelType.PRIMARY_STREAM_CHANNEL
            }
        }
    }

    /**
     * 获取直播视频质量描述列表
     * @return List<String>
     */
    fun getQualityList():List<String>{
        return mutableListOf("标清(960*540)","高清(1280*720)","超高清(1920*1080)")
    }

    /**
     * 获取码流通道列表
     * @return List<String>
     */
    fun getChannelTypeList():List<String>{
        return mutableListOf("主码流通道","副码流通道","扩展码流通道")
    }
}