package com.slodon.b2b2c.vo.goods;

import com.slodon.b2b2c.core.util.FileUrlUtil;
import com.slodon.b2b2c.goods.pojo.GoodsPlatform;
import com.slodon.b2b2c.goods.pojo.ProductPlatform;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

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

/**
 *
 * 封装商品库列表VO对象
 * @author wuxy
 * @date 2021.10.26 17:47
 */
@Data
public class GoodsPlatformVO {

    @ApiModelProperty("平台库商品ID")
    private Long platformGoodsId;

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

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

    @ApiModelProperty("品牌ID")
    private Integer brandId;

    @ApiModelProperty("品牌名称")
    private String brandName;

    @ApiModelProperty("1级分类ID")
    private Integer categoryId1;

    @ApiModelProperty("2级分类ID")
    private Integer categoryId2;

    @ApiModelProperty("3级分类ID")
    private Integer categoryId3;

    @ApiModelProperty("商品所属分类路径")
    private String categoryPath;

    @ApiModelProperty("售价")
    private BigDecimal goodsPrice;

    @ApiModelProperty("状态：1-待刊登；2-已刊登；3-已下架")
    private Integer state;

    @ApiModelProperty("商品主图路径，每个SPU一张主图")
    private String mainImage;

    @ApiModelProperty("下架原因")
    private String offlineReason;

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

    @ApiModelProperty("是否是虚拟商品：1-实物商品；2-虚拟商品")
    private Integer isVirtualGoods;

    @ApiModelProperty("规格列表")
    private List<ProductPlatformVO> productList;

    public GoodsPlatformVO(GoodsPlatform goodsPlatform) {
        this.platformGoodsId = goodsPlatform.getPlatformGoodsId();
        this.goodsName = goodsPlatform.getGoodsName();
        this.goodsBrief = goodsPlatform.getGoodsBrief();
        this.brandId = goodsPlatform.getBrandId();
        this.brandName = goodsPlatform.getBrandName();
        this.categoryId1 = goodsPlatform.getCategoryId1();
        this.categoryId2 = goodsPlatform.getCategoryId2();
        this.categoryId3 = goodsPlatform.getCategoryId3();
        this.categoryPath = goodsPlatform.getCategoryPath();
        this.goodsPrice = goodsPlatform.getGoodsPrice();
        this.state = goodsPlatform.getState();
        this.mainImage = FileUrlUtil.getFileUrl(goodsPlatform.getMainImage(), null);
        this.offlineReason = goodsPlatform.getOfflineReason();
        this.productId = goodsPlatform.getDefaultProductId();
        this.isVirtualGoods = goodsPlatform.getIsVirtualGoods();
    }

    @Data
    public static class ProductPlatformVO {
        @ApiModelProperty("平台库货品id")
        private Long platformProductId;

        @ApiModelProperty("平台库商品ID")
        private Long platformGoodsId;

        @ApiModelProperty("规格值，用逗号分隔")
        private String specValues;

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

        @ApiModelProperty("是否默认货品：0-否；1-是")
        private Integer isDefault;

        @ApiModelProperty("商品条形码")
        private String barCode;

        public ProductPlatformVO(ProductPlatform productPlatform) {
            this.platformProductId = productPlatform.getPlatformProductId();
            this.platformGoodsId = productPlatform.getPlatformGoodsId();
            this.specValues = StringUtils.isEmpty(productPlatform.getSpecValues()) ? "默认" : productPlatform.getSpecValues();
            this.productPrice = productPlatform.getProductPrice();
            this.isDefault = productPlatform.getIsDefault();
            this.barCode = productPlatform.getBarCode();
        }
    }

}
