package config

import (
	"github.com/ilyakaznacheev/cleanenv"
)

type Config struct {
	AppName  string   `yaml:"app_name" env:"APP_NAME" env-default:"test"`
	Server   Server   `yaml:"server"`
	Database Database `yaml:"database"`
}

type Server struct {
	Port string `yaml:"port" env:"PORT" env-default:"3000"`
	Host string `yaml:"host" env:"HOST" env-default:"localhost"`
}

type Database struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	Name     string `yaml:"name"`
}

func MustLoad(path string) *Config {
	var config Config

	err := cleanenv.ReadConfig(path, &config)
	if err != nil {
		panic(err)
	}

	return &config
}
