package com.hys.app.converter.erp;

import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dos.OrderItemDO;
import com.hys.app.model.erp.dto.OrderItemDTO;
import com.hys.app.model.erp.dto.StockUpdateDTO;
import com.hys.app.model.erp.enums.StockOperateEnum;
import com.hys.app.model.erp.vo.OrderItemExcelVO;
import com.hys.app.model.erp.vo.OrderItemVO;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;

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

/**
 * 订单明细 Converter
 *
 * @author 张崧
 * 2024-01-24 16:39:38
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface OrderItemConverter {

    OrderItemDO convert(OrderItemDTO orderItemDTO);

    OrderItemVO convert(OrderItemDO orderItemDO);

    List<OrderItemVO> convertList(List<OrderItemDO> list);

    List<OrderItemExcelVO> convertExcel(List<OrderItemVO> list);

    WebPage<OrderItemVO> convertPage(WebPage<OrderItemDO> webPage);

    default List<StockUpdateDTO> convertStockUpdate(List<OrderItemDO> itemList){
        return itemList.stream().map(orderItemDO -> {
            StockUpdateDTO stockUpdateDTO = new StockUpdateDTO();

            stockUpdateDTO.setBatchId(orderItemDO.getBatchId());
            stockUpdateDTO.setOperate(StockOperateEnum.Reduce);
            stockUpdateDTO.setTip(orderItemDO.getProductName());
            stockUpdateDTO.setChangeNum(orderItemDO.getNum());

            return stockUpdateDTO;
        }).collect(Collectors.toList());
    }
}

