package com.platform.plugs.live.responseEntity;

import com.aliyuncs.live.model.v20161101.DescribeCasterChannelsResponse;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;

/**
 * Description:
 * Author:zj
 * Date:2019/2/25 15:36
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Channel {
    /**
     * 通道位置ID。布局应用通道ID，每个位置至多设置一个视频源，格式需符合“RV01...RV12”
     */
    private String channelId;
    /**
     * 视频源Id
     */
    private String resourceId;
    /**
     * 通道输出地址
     */
    private String streamUrl;

    private String rtmpUrl;

    public static Channel parse(DescribeCasterChannelsResponse.Channel channel) {
        Channel entity = new Channel();
        entity.setChannelId(channel.getChannelId());
        entity.setResourceId(channel.getResourceId());
        entity.setStreamUrl(channel.getStreamUrl());
        entity.setRtmpUrl(channel.getRtmpUrl());
        return entity;
    }

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