package com.slodon.b2b2c.vo.goods;

import com.slodon.b2b2c.core.constant.ImageSizeEnum;
import com.slodon.b2b2c.core.util.FileUrlUtil;
import com.slodon.b2b2c.goods.pojo.Goods;
import com.slodon.b2b2c.goods.pojo.GoodsRank;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 *
 * 封装榜单详情页VO对象
 * @author wuxy
 */
@Data
public class FrontGoodsRankVO {

    @ApiModelProperty("榜单id")
    private Integer rankId;

    @ApiModelProperty("榜单名称")
    private String rankName;

    @ApiModelProperty("榜单分类id")
    private Integer categoryId;

    @ApiModelProperty("榜单分类名称")
    private String categoryName;

    @ApiModelProperty("描述")
    private String description;

    @ApiModelProperty("背景图")
    private String backgroundImage;

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

    public FrontGoodsRankVO(GoodsRank goodsRank) {
        this.rankId = goodsRank.getRankId();
        this.rankName = goodsRank.getRankName();
        this.categoryId = goodsRank.getCategoryId();
        this.categoryName = goodsRank.getCategoryName();
        this.description = goodsRank.getDescription();
        this.backgroundImage = FileUrlUtil.getFileUrl(goodsRank.getBackgroundImage(), null);
    }

    @Data
    public static class FrontRankGoodsVO {

        @ApiModelProperty("商品id")
        private Long goodsId;

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

        @ApiModelProperty("商品广告语")
        private String goodsBrief;

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

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

        @ApiModelProperty("销量")
        private Integer saleNum;

        @ApiModelProperty("货品id")
        private Long productId;

        @ApiModelProperty("上榜理由")
        private String rankReason;

        public FrontRankGoodsVO(Goods goods) {
            this.goodsId = goods.getGoodsId();
            this.goodsName = goods.getGoodsName();
            this.goodsBrief = goods.getGoodsBrief();
            this.goodsImage = FileUrlUtil.getFileUrl(goods.getMainImage(), ImageSizeEnum._300x300);
            this.productPrice = goods.getGoodsPrice();
            this.saleNum = goods.getActualSales() + goods.getVirtualSales();
            this.productId = goods.getDefaultProductId();
        }
    }
}
