package com.slodon.b2b2c.vo.video;

import com.slodon.b2b2c.core.util.FileUrlUtil;
import com.slodon.b2b2c.core.util.StringUtil;
import com.slodon.b2b2c.video.pojo.SvideoVideo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 * 封装短视频详情Vo对象
 * @author wuxy
 */
@Data
public class SVideoDetailVO implements Serializable {

    private static final long serialVersionUID = 1349519250118986633L;
    @ApiModelProperty("视频id")
    private Integer videoId;

    @ApiModelProperty("视频名称")
    private String videoName;

    @ApiModelProperty("视频地址")
    private String videoPath;

    @ApiModelProperty("视频地址")
    private String videoPathUrl;

    @ApiModelProperty("封面图地址")
    private String videoImage;

    @ApiModelProperty("封面图地址")
    private List<String> videoImageUrl;

    @ApiModelProperty("主题封面地址")
    private String videoThemeImage;

    @ApiModelProperty("主题封面地址")
    private String videoThemeImageUrl;

    @ApiModelProperty("视频简介")
    private String introduction;

    @ApiModelProperty("标签id")
    private Integer labelId;

    @ApiModelProperty("标签名称")
    private String labelName;

    @ApiModelProperty("视频类型:1-视频;2-图文")
    private Integer videoType;

    @ApiModelProperty("正文内容")
    private String videoContent;

    @ApiModelProperty("图片信息(json存储)")
    private String imageInfo;

    @ApiModelProperty("宽度")
    private Integer width;

    @ApiModelProperty("高度")
    private Integer height;

    @ApiModelProperty("商品列表")
    private List<VideoGoodsVO> goodsList;

    public SVideoDetailVO(SvideoVideo svideoVideo) {
        this.videoId = svideoVideo.getVideoId();
        this.videoName = svideoVideo.getVideoName();
        this.videoPath = svideoVideo.getVideoPath();
        this.videoPathUrl = FileUrlUtil.getFileUrl(svideoVideo.getVideoPath(), null);
        this.videoImage = svideoVideo.getVideoImage();
        this.videoImageUrl = dealImages(svideoVideo.getVideoImage());
        this.videoThemeImage = svideoVideo.getVideoThemeImage();
        this.videoThemeImageUrl = FileUrlUtil.getFileUrl(svideoVideo.getVideoThemeImage(), null);
        this.introduction = svideoVideo.getIntroduction();
        this.labelId = svideoVideo.getLabelId();
        this.labelName = svideoVideo.getLabelName();
        this.videoType = svideoVideo.getVideoType();
        this.videoContent = svideoVideo.getVideoContent();
        this.imageInfo = svideoVideo.getImageInfo();
        this.width = svideoVideo.getWidth();
        this.height = svideoVideo.getHeight();
    }

    public static List<String> dealImages(String images) {
        List<String> list = new ArrayList<>();
        if (StringUtil.isEmpty(images)) return null;
        List<String> picList = Arrays.asList(images.split(","));
        picList.forEach(image -> {
            if (!StringUtil.isEmpty(image)) {
                list.add(FileUrlUtil.getFileUrl(image, null));
            }
        });
        return list;
    }
}
