package config

import (
	"github.com/joho/godotenv"
	"github.com/kelseyhightower/envconfig"
	"log"
)

type Config struct {
	Port        string `envconfig:"PORT" default:"8080"`
	DatabaseURL string `envconfig:"DATABASE_URL" required:"true"`
	RedisURL    string `envconfig:"REDIS_URL"    required:"true"`
	SecretKey   string `envconfig:"SECRET_KEY"   required:"true"`
	BotToken    string `envconfig:"BOT_TOKEN"    required:"true"`
}

func Load() (*Config, error) {
	// Load .env file first, if it exists
	_ = godotenv.Load()

	var cfg Config
	if err := envconfig.Process("", &cfg); err != nil {
		return nil, err
	}

	log.Println("Configuration loaded successfully")
	return &cfg, nil
}
