package com.platform.plugs.live.responseEntity;

import com.aliyuncs.live.model.v20161101.DescribeCasterStreamUrlResponse;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

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

/**
 * @Author TONG
 * @Date 2019/3/7 16:20
 **/
@Data
public class CasterStream {
    /** 正式输出*/
    public static Integer PGM_OUTPUTTYPE = 1;
    /** 预览输出*/
    public static Integer PVW_OUTPUTTYPE = 0;
    /** 场景Id*/
    private String sceneId;
    /** 输出流地址*/
    private String streamUrl;
    /** rtmp地址*/
    private String rtmpUrl;
    /**是否正式输出。0：输出预览 1：输出正式*/
    private Integer outputType;
    /** 播放地址列表*/
    private List<StreamInfo> streamInfos;
    public static CasterStream parse(DescribeCasterStreamUrlResponse.CasterStream data) {
        CasterStream casterStream = new CasterStream();
        casterStream.setSceneId(data.getSceneId());
        casterStream.setStreamUrl(data.getStreamUrl());
        casterStream.setRtmpUrl(data.getRtmpUrl());
        casterStream.setOutputType(data.getOutputType());
        List<StreamInfo> streamInfos = new ArrayList<>();
        if(data.getStreamInfos() != null && data.getStreamInfos().size() > 0) {
            for (DescribeCasterStreamUrlResponse.CasterStream.StreamInfo obj : data.getStreamInfos()) {
                StreamInfo streamInfo = StreamInfo.parse(obj);
                streamInfos.add(streamInfo);
            }
        }
        casterStream.setStreamInfos(streamInfos);
        return casterStream;
    }

    public String getStreamUrl() {
        if (StringUtils.isNotBlank(this.streamUrl)) {
            return this.streamUrl.replaceAll("http://", "https://");
        }
        return null;
    }
}
