package config

import (
	"time"

	"github.com/zeromicro/go-zero/core/stores/cache"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/rest"
)

type Config struct {
	rest.RestConf
	// Redis 配置
	RedisConf redis.RedisConf
	// Redis Cluster (Cache)
	Cache                   cache.CacheConf
	CacheExpireTime         time.Duration
	CacheWithNotFoundExpiry time.Duration

	Mongo struct {
		Schema                           string
		User                             string
		Password                         string
		Host                             string
		Port                             string
		Database                         string
		ReplicaName                      string
		MaxStaleness                     time.Duration
		MaxPoolSize                      uint64
		MinPoolSize                      uint64
		MaxConnIdleTime                  time.Duration
		Compressors                      []string
		EnableStandardReadWriteSplitMode bool
		ConnectTimeoutMs                 int64
	}

	// 密碼加密層數
	Bcrypt struct {
		Cost int
	}

	GoogleAuth struct {
		ClientID string
		AuthURL  string
	}

	LineAuth struct {
		ClientID     string
		ClientSecret string
		RedirectURI  string
	}

	// JWT Token 配置
	Token struct {
		AccessSecret       string
		RefreshSecret      string
		AccessTokenExpiry  time.Duration
		RefreshTokenExpiry time.Duration
		OneTimeTokenExpiry time.Duration
		MaxTokensPerUser   int
		MaxTokensPerDevice int
	}

	// RoleConfig 角色配置
	RoleConfig struct {
		// UID 前綴 (例如: AM, RL)
		UIDPrefix string

		// UID 數字長度
		UIDLength int

		// 管理員角色 UID
		AdminRoleUID string

		// 管理員用戶 UID
		AdminUserUID string

		// 預設角色名稱
		DefaultRoleName string
	}
	SMTPConfig struct {
		Enable           bool
		GoroutinePoolNum int
		Host             string
		Port             int
		Username         string
		Password         string
		Sender           string
		SenderName       string
	}

	DeliveryConfig struct {
		MaxRetries    int           `json:"max_retries"`    // 最大重試次數
		InitialDelay  time.Duration `json:"initial_delay"`  // 初始重試延遲 (100ms)
		BackoffFactor float64       `json:"backoff_factor"` // 指數退避因子 (2.0)
		MaxDelay      time.Duration `json:"max_delay"`      // 最大延遲時間
		Timeout       time.Duration `json:"timeout"`        // 單次發送超時時間
		EnableHistory bool          `json:"enable_history"` // 是否啟用歷史記錄
	}

	AmazonS3Settings struct {
		Region           string
		Bucket           string
		CloudFrontDomain string
		CloudFrontURI    string
		BucketURI        string
		AccessKey        string
		SecretKey        string
		CloudFrontID     string
	}

	// Cassandra 配置
	Cassandra struct {
		Hosts     []string
		Port      int
		Keyspace  string
		Username  string
		Password  string
		UseAuth   bool
	}

	// Centrifugo 配置
	Centrifugo struct {
		APIURL string
		APIKey string
	}
}
