package com.slodon.b2b2c.vo.video;

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

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * 封装视频播放页VO对象
 * @author wuxy
 */
@Data
public class VideoPlayPageVO implements Serializable {

    private static final long serialVersionUID = -4458825898933250195L;
    @ApiModelProperty("作者信息")
    private AuthorInfoVO authorInfo;

    @ApiModelProperty("视频信息")
    private VideoInfoVO videoInfo;

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

    @ApiModelProperty("当前登录会员头像")
    private String memberAvatar;

    @Data
    public static class AuthorInfoVO implements Serializable {

        private static final long serialVersionUID = 6915994548515682537L;
        @ApiModelProperty("作者id")
        private Integer authorId;

        @ApiModelProperty("会员名称")
        private String memberName;

        @ApiModelProperty("会员昵称")
        private String memberNickname;

        @ApiModelProperty("会员头像")
        private String memberAvatar;

        @ApiModelProperty("粉丝数")
        private String fansNum;

        @ApiModelProperty("是否关注")
        private Boolean isFollow;

        public AuthorInfoVO(Author author) {
            this.authorId = author.getAuthorId();
            this.memberName = author.getMemberName();
            this.memberNickname = author.getMemberNickname();
            this.memberAvatar = author.getMemberAvatar().startsWith("http") ? author.getMemberAvatar() : FileUrlUtil.getFileUrl(author.getMemberAvatar(), null);
            this.fansNum = author.getFansNum() < 10000 ? author.getFansNum().toString()
                    : new BigDecimal(author.getFansNum()).divide(new BigDecimal(10000), 1, RoundingMode.FLOOR) + "w";
        }
    }

    @Data
    public static class VideoInfoVO implements Serializable {

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

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

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

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

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

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

        @ApiModelProperty("点赞数")
        private String likeNum;

        @ApiModelProperty("评论数")
        private String commentNum;

        @ApiModelProperty("分享数")
        private String shareNum;

        @ApiModelProperty("状态:1待审核，2正常，3拒绝，4禁止显示")
        private Integer state;

        @ApiModelProperty("禁止理由,拒绝理由")
        private String remark;

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

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

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

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

        @ApiModelProperty("是否自己的视频")
        private Boolean isSelf = false;

        @ApiModelProperty("是否点赞")
        private Boolean isLike = false;

        public VideoInfoVO(SvideoVideo svideoVideo) {
            this.videoId = svideoVideo.getVideoId();
            this.videoName = svideoVideo.getVideoName();
            this.videoPath = FileUrlUtil.getFileUrl(svideoVideo.getVideoPath(), null);
            this.videoImage = dealVideoImage(svideoVideo.getVideoImage());
            this.videoThemeImage = FileUrlUtil.getFileUrl(svideoVideo.getVideoThemeImage(), null);
            this.introduction = svideoVideo.getIntroduction();
            this.likeNum = svideoVideo.getLikeNum() < 10000 ? svideoVideo.getLikeNum().toString()
                    : new BigDecimal(svideoVideo.getLikeNum()).divide(new BigDecimal(10000), 1, RoundingMode.FLOOR) + "w";
            this.commentNum = svideoVideo.getCommentNum() < 10000 ? svideoVideo.getCommentNum().toString()
                    : new BigDecimal(svideoVideo.getCommentNum()).divide(new BigDecimal(10000), 1, RoundingMode.FLOOR) + "w";
            this.shareNum = svideoVideo.getShareNum() < 10000 ? svideoVideo.getShareNum().toString()
                    : new BigDecimal(svideoVideo.getShareNum()).divide(new BigDecimal(10000), 1, RoundingMode.FLOOR) + "w";
            this.state = svideoVideo.getState();
            this.remark = svideoVideo.getRemark();
            this.videoType = svideoVideo.getVideoType();
            this.videoContent = svideoVideo.getVideoContent();
            this.width = svideoVideo.getWidth();
            this.height = svideoVideo.getHeight();
        }

        public static List<String> dealVideoImage(String videoImage) {
            List<String> list = new ArrayList<>();
            for (String str : videoImage.split(",")) {
                if (StringUtil.isEmpty(str)) continue;
                list.add(FileUrlUtil.getFileUrl(str, null));
            }
            return list;
        }
    }

    @Data
    public static class GoodsInfoVO implements Serializable {

        private static final long serialVersionUID = -3707645612378581018L;
        @ApiModelProperty("商品id")
        private Long goodsId;

        @ApiModelProperty("商品名称")
        private String goodsName;

        @ApiModelProperty("商品图片")
        private String goodsImage;

        @ApiModelProperty("商品价格")
        private BigDecimal goodsPrice;

        @ApiModelProperty("默认货品id")
        private Long defaultProductId;

        @ApiModelProperty("商品库存")
        private Integer goodsStock;

        @ApiModelProperty("店铺ID")
        private Long storeId;

        @ApiModelProperty("店铺名称")
        private String storeName;

        public GoodsInfoVO(Goods goods) {
            this.goodsId = goods.getGoodsId();
            this.goodsName = goods.getGoodsName();
            this.goodsImage = FileUrlUtil.getFileUrl(goods.getMainImage(), null);
            this.goodsPrice = goods.getGoodsPrice();
            this.defaultProductId = goods.getDefaultProductId();
            this.goodsStock = goods.getGoodsStock();
            this.storeId = goods.getStoreId();
            this.storeName = goods.getStoreName();
        }
    }
}
