package config

import (
	"os"

	"gopkg.in/yaml.v3"
)

type DatabaseConfig struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	Database string `yaml:"database"`
}

type Limit struct {
	CommentNumMin int `yaml:"commentNumMin"`
	CommentNumMax int `yaml:"commentNumMax"`
	LikeNumMin    int `yaml:"likeNumMin"`
	LikeNumMax    int `yaml:"likeNumMax"`
	FollowNumMin  int `yaml:"followNumMin"`
	FollowNumMax  int `yaml:"followNumMax"`
	ViweTimeMax   int `yaml:"viweTimeMax"`
	ViweTimeMin   int `yaml:"viweTimeMin"`
	BrowserRunMax int `yaml:"browserRunMax"`
}

type Clash struct {
	Host    string `yaml:"host"`
	Port    int    `yaml:"port"`
	Secret  string `yaml:"secret"`
	ExePath string `yaml:"exePath"`
}

type AppConfig struct {
	Port       int              `yaml:"port"`
	Database   DatabaseConfig   `yaml:"database"`
	Limit      Limit            `yaml:"limit"`
	Clash      Clash            `yaml:"clash"`
	BitBrowser BitBrowserConfig `yaml:"bitBrowser"`
	AdsPower   AdsPowerConfig   `yaml:"adsPower"`
	Firstmail  FirstmailConfig  `yaml:"firstmail"`
}

type BitBrowserConfig struct {
	ApiUrl   string `yaml:"apiUrl"`
	ApiToken string `yaml:"apiToken"`
}

type AdsPowerConfig struct {
	ApiUrl   string `yaml:"apiUrl"`
	ApiToken string `yaml:"apiToken"`
}

type FirstmailConfig struct {
	ApiUrl   string `yaml:"apiUrl"`
	ApiToken string `yaml:"apiToken"`
}

func LoadConfig() (*AppConfig, error) {
	// 读取文件内容
	data, err := os.ReadFile("config.yaml")
	if err != nil {
		return nil, err
	}

	// 解析 YAML
	var cfg AppConfig
	if err := yaml.Unmarshal(data, &cfg); err != nil {
		return nil, err
	}

	return &cfg, nil
}
