package config

import (
	"os"

	"gopkg.in/yaml.v3"
)

var ConfigManager = &configManager{}

type Config struct {
	Admin            int64  `yaml:"admin"`
	SteamApiKey      string `yaml:"steam_api_key"`
	ProxyAddr        string `yaml:"proxy_addr"`
	NapcatWsSrv      string `yaml:"napcat_ws_srv"`
	NapcatHttpSrv    string `yaml:"napcat_http_srv"`
	OpenaiApiKey     string `yaml:"openai_api_key"`
	OpenaiApiBaseUrl string `yaml:"openai_api_base_url"`
	OpenaiModelName  string `yaml:"openai_model_name"`
	OpenaiPrompt     string `yaml:"openai_prompt"`
}

func init() {
	err := ConfigManager.LoadConfig("config.yml")
	if err != nil {
		panic(err)
	}
}

type configManager struct {
	// propertys map[string]string
	config *Config
}

func (cm *configManager) LoadConfig(path string) error {
	data, err := os.ReadFile(path)
	if err != nil {
		return err
	}

	err = yaml.Unmarshal(data, &cm.config)
	if err != nil {
		return err
	}
	return nil
}

func (cm *configManager) GetConfig() *Config {
	return cm.config
}
