package com.cxyxiaomo.epp.common.vo;

import com.cxyxiaomo.epp.common.pojo.OrderDetail;
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 OrderDetailVO implements Serializable {
    private Long id;
    private String orderId;
    private String goodId;
    private Integer goodCount;
    private Double unitPrice;

    public static OrderDetailVO convertFrom(OrderDetail orderDetail) {
        if (orderDetail == null) {
            return null;
        }
        OrderDetailVO orderDetailVO = new OrderDetailVO();
        BeanUtils.copyProperties(orderDetail, orderDetailVO);
        orderDetailVO.setOrderId(String.valueOf(orderDetail.getOrderId()));
        orderDetailVO.setGoodId(String.valueOf(orderDetail.getGoodId()));
        return orderDetailVO;
    }

    public static List<OrderDetailVO> convertFrom(List<OrderDetail> orderDetailList) {
        if (orderDetailList == null) {
            return null;
        }
        return orderDetailList.stream().map(OrderDetailVO::convertFrom).collect(Collectors.toList());
    }
}
