package com.fs.fastGpt.domain;

import com.fs.common.annotation.Excel;
import com.fs.common.core.domain.BaseEntity;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
public class FastGptPushTokenTotal extends BaseEntity {

    /** 计价：1 元 = 10 万 token */
    public static final BigDecimal TOKEN_PER_YUAN = new BigDecimal("100000");

    private Long id;
    private Integer type;
    private Long qwUserId;
    private Long companyId;
    @Excel(name = "公司名称")
    private String companyName;
    @Excel(name = "token消耗数")
    private Long count;
    @Excel(name = "耗费金额(元)")
    private Double amount;
    private Integer status;
    @Excel(name = "生成时间")
    private String statTime;

    /**
     * 按 token 消耗计算金额（不以各行已四舍五入的金额再累加，避免精度丢失）
     * 规则：1 元 = 10 万 token，保留两位小数（四舍五入）
     */
    public static Double calcAmountByCount(Long count) {
        if (count == null) {
            return null;
        }
        return BigDecimal.valueOf(count)
                .divide(TOKEN_PER_YUAN, 2, RoundingMode.HALF_UP)
                .doubleValue();
    }

}
