package com.ruoyi.project.business.domain.vo.project;

import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import com.ruoyi.project.business.domain.TcProjectEquipment;
import java.math.BigDecimal;
import java.math.RoundingMode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.poi.ss.usermodel.HorizontalAlignment;

/**
 * @author : fangk
 * @date : 2024/7/2 18:02
 * @desc : 项目设备信息 res
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProjectEquipmentRes {

    private Long id;

    /**
     * 关联项目Id
     */
    private Long projectId;

    @Excel(name = "规格", i18nCode = "project.stand")
    private String standard;

    @Excel(name = "梯形", i18nCode = "quotation.elevatorMode")
    private String elevatorModel;

    /**
     * 设备类型
     */
    @Excel(name = "设备类型", i18nCode = "project.equipmentType", dictType = "intentional_product")
    private String equipmentType;

    /**
     * 设备数量
     */
    @Excel(name = "设备数量", i18nCode = "project.equipmentQuantity")
    private Long equipmentQuantity;

    /**
     * 币种
     */
    @Excel(name = "币种", i18nCode = "project.currency", dictType = "currency_type")
    private String currency;

    /**
     * 金额
     */
    private BigDecimal amount;

    @Excel(name = "单价", i18nCode = "project.unit.price", align = HorizontalAlignment.RIGHT)
    private String amountStr;

    /**
     * 金额
     */
    private BigDecimal priceTotal;

    @Excel(name = "总价", i18nCode = "project.priceTotal", align = HorizontalAlignment.RIGHT)
    private String priceTotalStr;


    public static ProjectEquipmentRes from(TcProjectEquipment equipment,String currency) {
        BigDecimal priceTotal = BigDecimal.ZERO;
        try {
            priceTotal = BigDecimal.valueOf(equipment.getEquipmentQuantity())
                .multiply(equipment.getAmount())
                .setScale(2, RoundingMode.DOWN);
        } catch (Exception e) {
            // ignore
        }
        return new ProjectEquipmentRes(
            equipment.getId(),
            equipment.getProjectId(),
            equipment.getStandard(),
            equipment.getElevatorModel(),
            equipment.getEquipmentType(),
            equipment.getEquipmentQuantity(),
            currency,
            equipment.getAmount(),
            "",
            priceTotal, ""
        );
    }
}
