package com.ruoyi.generator.service.front;

import org.springframework.stereotype.Component;

@Component
public class AiCostCalculator
{
    private static final double DEEPSEEK_CHAT_INPUT_CENTS_PER_1K = 0.1D;
    private static final double DEEPSEEK_CHAT_OUTPUT_CENTS_PER_1K = 0.6D;

    public int estimateCostCents(String provider, String model, Integer inputTokens, Integer outputTokens)
    {
        if (inputTokens == null && outputTokens == null)
        {
            return 0;
        }
        int input = inputTokens == null ? 0 : Math.max(inputTokens, 0);
        int output = outputTokens == null ? 0 : Math.max(outputTokens, 0);
        if (input == 0 && output == 0)
        {
            return 0;
        }
        double cents = input / 1000D * DEEPSEEK_CHAT_INPUT_CENTS_PER_1K
                + output / 1000D * DEEPSEEK_CHAT_OUTPUT_CENTS_PER_1K;
        return Math.max(1, (int) Math.ceil(cents));
    }
}
