package com.cool.store.vo.order;

import com.alibaba.excel.annotation.ExcelProperty;
import com.cool.store.utils.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Auther zx_szh
 * @Date 2026/4/3 10:15
 * @Version 1.0
 */
@Data
public class OrderDeviceDetailExportVO {

    @ApiModelProperty("费用名称")
    @ExcelProperty(value = "费用类型", index = 0)
    private String expenseTypeName;

    @ApiModelProperty("配置大类名称")
    @ExcelProperty(value = "配置大类", index = 1)
    private String categoryName;

    @ApiModelProperty("配置项名称")
    @ExcelProperty(value = "配置项", index = 2)
    private String itemName;

    @ApiModelProperty("配置选型名称")
    @ExcelProperty(value = "配置项选型", index = 3)
    private String optionName;

    @ApiModelProperty("原单价")
    @ExcelProperty(value = "原单价", index = 4)
    private BigDecimal originalOptionPrice;

    @ApiModelProperty("默认数量")
    @ExcelProperty(value = "优惠数量", index = 5)
    private BigDecimal defaultQuantity;

    @ApiModelProperty("优惠单价")
    @ExcelProperty(value = "优惠单价", index = 6)
    private BigDecimal optionPrice;

    @ApiModelProperty("下单数量")
    @ExcelProperty(value = "下单数量", index = 7)
    private BigDecimal quantity;

    @ApiModelProperty("价格合计")
    @ExcelProperty(value = "价格合计", index = 8)
    private BigDecimal amount;


    public static List<OrderDeviceDetailExportVO> convert(List<OrderDeviceDetailVO> voList){
        if (CollectionUtils.isEmpty(voList)){
            return new ArrayList<>();
        }
        List<OrderDeviceDetailExportVO> result = new ArrayList<>();
        voList.forEach(x->{
            x.getItems().forEach(y->{
                OrderDeviceDetailExportVO orderDeviceConfigItemVO = new OrderDeviceDetailExportVO();
                BeanUtil.copyProperties(y,orderDeviceConfigItemVO);
                orderDeviceConfigItemVO.setExpenseTypeName(x.getExpenseTypeName());
                result.add(orderDeviceConfigItemVO);
            });
        });
        return result;
    }
}
