package config

import (
	"fmt"

	"github.com/kelseyhightower/envconfig"
)

// Config holds all application configuration loaded from environment variables.
type Config struct {
	DatabaseURL string `envconfig:"database_url" required:"true"`
	Port        string `envconfig:"port" default:"8080"`
	CorsOrigin  string `envconfig:"cors_origin" default:"*"`
	LogLevel    string `envconfig:"log_level" default:"info"`
}

// Load reads configuration from environment variables and returns a populated Config.
func Load() (*Config, error) {
	var cfg Config
	if err := envconfig.Process("", &cfg); err != nil {
		return nil, fmt.Errorf("failed to load config: %w", err)
	}
	return &cfg, nil
}
