package config

import (
	"codeberg.org/ungo/env"
	"codeberg.org/ungo/env/dotenv"
)

type Config struct {
	Database DatabaseConfig `env:"DATABASE_"`
	Server   ServerConfig   `env:"SERVER_"`
	Discord  DiscordConfig  `env:"DISCORD_"`
	Auth     AuthConfig     `env:"AUTH_"`
}

type DatabaseConfig struct {
	RedisURL    string `env:"REDIS_URL"`
	PostgresURL string `env:"POSTGRES_URL,required"`
}

type ServerConfig struct {
	Port    int    `env:"PORT,default=8080"`
	Address string `env:"ADDRESS,default=127.0.0.1"`
}

type DiscordConfig struct {
	ClientID     string `env:"CLIENT_ID,required"`
	ClientSecret string `env:"CLIENT_SECRET,required"`
	RedirectURI  string `env:"REDIRECT_URI,default=http://localhost:8080/auth/callback"`
}

type AuthConfig struct {
	PasetoKey string `env:"PASETO_KEY,required"`
}

func LoadConfig() Config {
	var cfg Config
	if err := env.Load(&cfg); err != nil {
		panic(err)
	}

	return cfg
}

func init() {
	if err := dotenv.Load(); err != nil {
		panic(err)
	}
}
