package initialize

import (
	"gitea.pena/PenaSide/common/mongo"
	"github.com/caarlos0/env/v8"
	"github.com/joho/godotenv"
	"log"
)

type Config struct {
	IsProd            bool   `env:"IS_PROD" envDefault:"false"`
	S3Endpoint        string `env:"S3_ENDPOINT" envDefault:"localhost:9000"`
	S3AccessKey       string `env:"S3_ACCESS_KEY" envDefault:"minioadmin"`
	S3SecretKey       string `env:"S3_SECRET_KEY" envDefault:"minioadmin"`
	S3Token           string `env:"S3_TOKEN" envDefault:""`
	RedisHost         string `env:"REDIS_HOST" envDefault:"localhost:6379"`
	RedisPassword     string `env:"REDIS_PASSWORD" envDefault:"admin"`
	RedisDB           int    `env:"REDIS_DB" envDefault:"2"`
	ClientHttpUrl     string `env:"CLIENT_HTTP_URL" envDefault:"localhost:3000"`
	AdminHttpUrl      string `env:"ADMIN_HTTP_URL" envDefault:"localhost:3001"`
	TelegramToken     string `env:"TELEGRAM_TOKEN" envDefault:"7127966184:AAG1steOCH4wDvHRe9QcsXJPS4dWRyRYsqg"`
	TelegramChannelID int64  `env:"TELEGRAM_CHANNEL_ID" envDefault:"1001344671794"`
	ExternalCfg       ExternalCfg
}

type ExternalCfg struct {
	Database mongo.Configuration
}

func LoadConfig() (*Config, error) {
	if err := godotenv.Load(); err != nil {
		log.Print("No .env file found")
	}
	var config Config
	if err := env.Parse(&config); err != nil {
		return nil, err
	}
	return &config, nil
}
