package com.slodon.b2b2c.vo.goods;

import com.slodon.b2b2c.goods.pojo.GoodsSpec;
import com.slodon.b2b2c.goods.pojo.GoodsSpecValue;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;

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

/**
 * @author cwl
 *
 * 封装商品规格列表VO对象
 */
@Data
public class GoodsSpecVO {

    @ApiModelProperty("规格id")
    private Integer specId;

    @ApiModelProperty("规格名称")
    private String specName;

    @ApiModelProperty("店铺id，0为系统创建")
    private Long storeId;

    @ApiModelProperty("状态 0-不展示 1-展示，可以删除，但是必须没有其他商品使用")
    private Integer state;

    @ApiModelProperty("排序")
    private Integer sort;

    @ApiModelProperty("规则值")
    private List<GoodsSpecValueVO> valueList = new ArrayList<>();

    public GoodsSpecVO(GoodsSpec goodsSpec, List<GoodsSpecValue> specValues) {
        this.specId = goodsSpec.getSpecId();
        this.specName = goodsSpec.getSpecName();
        this.state = goodsSpec.getState();
        this.sort = goodsSpec.getSort();
        this.storeId = goodsSpec.getStoreId();
        if (!CollectionUtils.isEmpty(specValues)) {
            specValues.forEach(specValue -> {
                this.valueList.add(new GoodsSpecValueVO(specValue));
            });
        }
    }

    /**
     * 规格值
     */
    @Data
    public static class GoodsSpecValueVO implements Serializable {

        private static final long serialVersionUID = -1966536642799486725L;
        @ApiModelProperty("规格值id")
        private Integer specValueId;

        @ApiModelProperty("规格值")
        private String specValue;

        public GoodsSpecValueVO(GoodsSpecValue goodsSpecValue) {
            this.specValueId = goodsSpecValue.getSpecValueId();
            this.specValue = goodsSpecValue.getSpecValue();
        }
    }
}