package com.cxyxiaomo.epp.common.vo;

import com.cxyxiaomo.epp.common.pojo.GoodCategory;
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 GoodCategoryVO implements Serializable {

    Long id;
    String categoryName;
    Integer order;

    public static GoodCategoryVO convertFrom(GoodCategory goodCategory) {
        if (goodCategory == null) {
            return null;
        }
        GoodCategoryVO goodCategoryVO = new GoodCategoryVO();
        BeanUtils.copyProperties(goodCategory, goodCategoryVO);
        return goodCategoryVO;
    }

    public static List<GoodCategoryVO> convertFrom(List<GoodCategory> goodCategoryList) {
        if (goodCategoryList == null) {
            return null;
        }
        List<GoodCategoryVO> goodCategoryVOList = goodCategoryList.stream().map(GoodCategoryVO::convertFrom).collect(Collectors.toList());
        return goodCategoryVOList;
    }
}
