package console

import (
	"fmt"
	"reflect"
	"strings"
)

type Formatter func(any) string

var formatters = map[reflect.Kind]Formatter{
	reflect.String:  func(v any) string { return fmt.Sprintf("%s", v) },
	reflect.Int:     func(v any) string { return fmt.Sprintf("%d", v) },
	reflect.Float64: func(v any) string { return fmt.Sprintf("%.2f", v) },
	// 可以添加更多类型的格式化函数
}

func Error() {

}

func Debug() {

}

func Log(msg string, a ...any) {
	builder := strings.Builder{}
	builder.WriteString(msg)

	for _, arg := range a {
		kind := reflect.TypeOf(arg).Kind()
		if fn, ok := formatters[kind]; ok {
			builder.WriteString(fn(arg))
		} else {
			builder.WriteString(fmt.Sprintf("%v", arg))
		}
	}

	fmt.Println(builder.String())
}
