package credit

import "math"

var modelArray = []string{
	"o1",
	"gpt-4o",
	"gpt-4.1",
	"o3-mini",
	"moonshot-v1-32k",
	"deepseek-r1",
	"moonshot-v1-8k",
	"gpt-4.1-mini",
	"gpt-3.5-turbo",
	"qwen-max",
	"doubao1.5-pro-256k",
	"deepseek-v3",
	"qwq-32b-preview",
	"gpt-4o-mini",
	"qwen2.5-14b-instruct-1m",
	"gpt-4.1-nano",
	"doubao1.5-pro",
	"doubao1.5-pro-32k",
	"chatglm3",
	"qwen-turbo",
	"doubao1.5-lite-32k",
}

var priceArray = []float64{
	0.0001,
	0.00001667,
	0.00001333,
	0.00000733,
	0.00000548,
	0.00000365,
	0.00000274,
	0.00000267,
	0.0000025,
	0.00000219,
	0.00000205,
	0.00000183,
	0.00000137,
	0.000001,
	0.00000068,
	0.00000067,
	0.00000046,
	0.00000046,
	0.00000023,
	0.00000014,
	0.00000014,
}

func getModelName() string {
	return "gpt-4o"
}

func GetModelPrice() (model string, price float64) {
	difyModelName := getModelName()
	for i, v := range modelArray {
		if v == difyModelName {
			return v, priceArray[i]
		}
	}

	return modelArray[0], priceArray[0]
}

func ComputePrice(price float64, tokens uint64) float64 {
	scale := float64(1000000)
	return math.Round(price*float64(tokens)*scale) / scale
}

// Subtraction() 保留小数点后6位的精确减法
func Subtraction(number1, number2 float64) float64 {
	d1 := number1 * 1000000
	d2 := number2 * 1000000
	res := math.Floor(d1-d2) / 1000000
	return res
}
