package com.platform.modules.live.dto;

import lombok.Data;
import lombok.ToString;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 查询导播台流信息 dto
 * @Author: yikaihong
 * @CreateDate: 2019/1/20 17:55
 * @Version: 1.0
 */
@Data
@ToString
public class DescribeCasterStreamResponseDto {

    private String sceneId;
    private String streamUrl;
    private String rtmpUrl;
    private String outputType;
    private List<StreamInfoResponseDto> streamInfos;

    public DescribeCasterStreamResponseDto(JSONObject jsonObject) {
        if (jsonObject.containsKey("SceneId")) {
            this.sceneId = jsonObject.getString("SceneId");
        }
        if (jsonObject.containsKey("StreamUrl")) {
            this.streamUrl = jsonObject.getString("StreamUrl");
        }
        if (jsonObject.containsKey("RtmpUrl")) {
            this.rtmpUrl = jsonObject.getString("RtmpUrl");
        }
        if (jsonObject.containsKey("OutputType")) {
            this.outputType = jsonObject.getString("OutputType");
        }
        if (jsonObject.containsKey("StreamInfos")) {
            JSONObject streamInfosObject = jsonObject.getJSONObject("StreamInfos");
            if (streamInfosObject != null && !streamInfosObject.isEmpty()) {
                JSONArray streamInfosArr = streamInfosObject.getJSONArray("StreamInfo");
                if (streamInfosArr != null && streamInfosArr.size() > 0) {
                    streamInfos = new ArrayList<>();
                    streamInfosArr.forEach(streamInfo -> {
                        if (streamInfo instanceof JSONObject) {
                            streamInfos.add(new StreamInfoResponseDto((JSONObject) streamInfo));
                        }
                    });
                }
            }
        }
    }
}