package config

import "time"

const (
	DefaultDBOperationTimeout = 30 * time.Second
)

type ConfigWrapper struct {
	*EcosystemConfig
}

type EcosystemConfig struct {
	ServerConfig   ServerConfig   `mapstructure:"server"`
	RdsConfig      DatabaseConfig `mapstructure:"rds"`
	VercelConfig   VercelConfig   `mapstructure:"vercel"`
	ServiceConfig  ServiceConfig  `mapstructure:"service"`
	BigQueryConfig BigQueryConfig `mapstructure:"bigquery"`
	GitConfig      GitConfig      `mapstructure:"git"`
	PingChatConfig PingChatConfig `mapstructure:"pingchat"`
}

type RegionConfig struct {
	DefaultRegion Region            `mapstructure:"defaultRegion"`
	RegionMap     map[string]Region `mapstructure:"regionMap"`
}

type PingChatConfig struct {
	AccessKey    string `mapstructure:"access_key"`
	AccessSecret string `mapstructure:"access_secret"`
}

type Region struct {
	Provider string `mapstructure:"provider"`
	Region   string `mapstructure:"region"`
}

type BigQueryConfig struct {
	Enable     bool   `mapstructure:"enable"`
	Credential string `mapstructure:"credential"`
}

type VercelConfig struct {
	AccessDetails `mapstructure:",squash"`
	RegionConfig  RegionConfig `mapstructure:"providerRegion"`
}

type AccessDetails struct {
	IntegrationID          string `mapstructure:"integration_id"`
	IntegrationSecret      string `mapstructure:"integration_secret"`
	IntegrationLinkPage    string `mapstructure:"integration_link_page"`
	IntegrationRedirectUri string `mapstructure:"integration_redirect_uri"`
}

type ServerConfig struct {
	LogLevel         string `mapstructure:"log_level" default:"info" validate:"oneof=debug info warn error fatal"`
	EnableDBQueryLog bool   `mapstructure:"enable_db_query_log" default:"false"`
	TiDBCloudHost    string `mapstructure:"tidb_cloud_host" default:"https://tidbcloud.com"`
	EnableAuditLog   bool   `mapstructure:"enableAuditLog" default:"true"`
	Project          string `mapstructure:"project"`

	SecretStore *SecretConfig `mapstructure:"secret"`
}

type SecretConfig struct {
	SecretName string `mapstructure:"aws_secret_name"`
	Region     string `mapstructure:"region"`
}

type DatabaseConfig struct {
	Host     string `mapstructure:"host" validate:"required"`
	User     string `mapstructure:"user" validate:"required"`
	Port     uint16 `mapstructure:"port" validate:"required"`
	Password string `mapstructure:"password"`
	Database string `mapstructure:"database" validate:"required"`
}

type ServiceConfig struct {
	GrpcConfig GrpcConfig `mapstructure:"grpc"`
	CMKArn     string     `mapstructure:"cmkArn" validate:"required"`
}

type GrpcConfig struct {
	AccountProviderAddr     string `mapstructure:"account_provider_addr" validate:"required"`
	AclSvcAddr              string `mapstructure:"acl_svc_addr" validate:"required"`
	DataApiSvcAddr          string `mapstructure:"data_api_svc_addr" validate:"required"`
	ServerlessSvcAddr       string `mapstructure:"serverless_svc_addr" validate:"required"`
	MgmtSvcAddr             string `mapstructure:"mgmt_svc_addr" validate:"required"`
	ServerlessGlobalSvcAddr string `mapstructure:"serverless_global_svc_addr" validate:"required"`
}

type GitConfig struct {
	GitHubAppConfig GitHubAppConfig `mapstructure:"github" required:"true"`
}

type GitHubAppConfig struct {
	WebhookSecret string `mapstructure:"webhook_secret" required:"true"`
	AppIdentifier int64  `mapstructure:"app_identifier" required:"true"`
	PrivateKey    string `mapstructure:"private_key" required:"true"`
	ClientID      string `mapstructure:"client_id" required:"true"`
	ClientSecret  string `mapstructure:"client_secret" required:"true"`
	Name          string `mapstructure:"name" required:"true"`
}
