package audit

import "gopkg.in/yaml.v2"

// config is copied from github.com/tidbcloud/infra-provider/infra-api/pkg/audit/server
type Config struct {
	LogDir string `yaml:"logDir"`
	// An empty BucketURL will delete the rotated log directly.
	// AWS: s3://{bucket}/{path}
	// GCP: gcs://{bucket}/{path}
	// Azure: azblob://{account}.blob.core.windows.net/{container}
	BucketURL string `yaml:"bucketURL"`
	Region    string `yaml:"region"`
	// TODO: RoleARN and ExternalID are AWS specific, should move to AWS field
	RoleARN    string `yaml:"roleARN"`
	ExternalID string `yaml:"externalID"`
	Azure      *Azure `yaml:"azure"`

	SlowLogMaxBackups int `yaml:"slowLogMaxBackups"`
	// if disk is cleanOldestLogPercent full, we clean the oldest audit log files directly.
	// Should in  range [0.0, 1.0]
	CleanOldestLogPercent   float64 `yaml:"cleanOldestLogPercent"`
	GracefulStopWaitSeconds int     `yaml:"gracefulStopWaitSeconds"`

	// This DO NOT support reload config now.
	// Zero will not serve metrics
	MetricsPort int `yaml:"metricsPort"`
}

type Azure struct {
	SASToken string `yaml:"sasToken"`
}

func (c *Config) ToYAML() ([]byte, error) {
	data, err := yaml.Marshal(c)
	return data, err
}
