package com.cxyxiaomo.epp.common.vo;

import com.cxyxiaomo.epp.common.pojo.Good;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

// 数据库关系映射

@Data
@NoArgsConstructor
@Accessors(chain = true) // 链式写法
// 微服务必须要实现Serializable
public class GoodVO implements Serializable {
    String id;
    String goodsName;
    Integer categoryId;
    String brand;
    String gallery;
    String brief;
    Boolean isOnSale;
    Integer sortOrder;
    String picUrl;
    Integer type;
    String unit;
    Double counterPrice;
    Double retailPrice;
    String detail;

    public static GoodVO convertFrom(Good good) {
        if (good == null) {
            return null;
        }
        GoodVO goodVO = new GoodVO();
        BeanUtils.copyProperties(good, goodVO);
        goodVO.setId(String.valueOf(good.getId()));
        return goodVO;
    }

    public static List<GoodVO> convertFrom(List<Good> goodList) {
        if (goodList == null) {
            return null;
        }
        List<GoodVO> goodVOList = goodList.stream().map(GoodVO::convertFrom).collect(Collectors.toList());
        return goodVOList;
    }
}
