package config

import "time"

type Config struct {
	App      AppConfig      `mapstructure:"app"`
	HTTP     HTTPConfig     `mapstructure:"http"`
	Log      LogConfig      `mapstructure:"log"`
	Auth     AuthConfig     `mapstructure:"auth"`
	Database DatabaseConfig `mapstructure:"database"`
	Redis    RedisConfig    `mapstructure:"redis"`
	JWT      JWTConfig      `mapstructure:"jwt"`
	OAuth    OAuthConfig    `mapstructure:"oauth"`
}

type AppConfig struct {
	Name        string `mapstructure:"name"`
	Environment string `mapstructure:"environment"`
	Version     string `mapstructure:"version"`
}

type HTTPConfig struct {
	Host              string        `mapstructure:"host"`
	Port              int           `mapstructure:"port"`
	ReadTimeout       time.Duration `mapstructure:"read_timeout"`
	WriteTimeout      time.Duration `mapstructure:"write_timeout"`
	ShutdownTimeout   time.Duration `mapstructure:"shutdown_timeout"`
	CORSAllowedOrigin []string      `mapstructure:"allowed_origins"`
}

type LogConfig struct {
	Level  string `mapstructure:"level"`
	Format string `mapstructure:"format"`
}

type AuthConfig struct {
	BypassSSO bool          `mapstructure:"bypass_sso"`
	DevUser   DevUserConfig `mapstructure:"dev_user"`
}

type DevUserConfig struct {
	ID    string   `mapstructure:"id"`
	Email string   `mapstructure:"email"`
	Name  string   `mapstructure:"name"`
	Roles []string `mapstructure:"roles"`
}

type DatabaseConfig struct {
	DSN             string        `mapstructure:"dsn"`
	MaxOpenConns    int           `mapstructure:"max_open_conns"`
	MaxIdleConns    int           `mapstructure:"max_idle_conns"`
	ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
}

type RedisConfig struct {
	Addr         string        `mapstructure:"addr"`
	Password     string        `mapstructure:"password"`
	DB           int           `mapstructure:"db"`
	DialTimeout  time.Duration `mapstructure:"dial_timeout"`
	ReadTimeout  time.Duration `mapstructure:"read_timeout"`
	WriteTimeout time.Duration `mapstructure:"write_timeout"`
}

type JWTConfig struct {
	AccessSecret        string        `mapstructure:"access_secret"`
	RefreshSecret       string        `mapstructure:"refresh_secret"`
	AccessTokenTTL      time.Duration `mapstructure:"access_token_ttl"`
	RefreshTokenTTL     time.Duration `mapstructure:"refresh_token_ttl"`
	RefreshGracePeriod  time.Duration `mapstructure:"refresh_grace_period"`
	SigningAlgorithm    string        `mapstructure:"signing_algorithm"`
	Issuer              string        `mapstructure:"issuer"`
	ClockSkewInSeconds  int64         `mapstructure:"clock_skew_seconds"`
	AllowInsecureSecret bool          `mapstructure:"allow_insecure_secret"`
}

type OAuthConfig struct {
	Enabled      bool     `mapstructure:"enabled"`
	ClientID     string   `mapstructure:"client_id"`
	ClientSecret string   `mapstructure:"client_secret"`
	RedirectURL  string   `mapstructure:"redirect_url"`
	Scopes       []string `mapstructure:"scopes"`
	BypassGoogle bool     `mapstructure:"bypass_google"` // For development: skip real Google OAuth
}
