package main

import (
	"os"

	"github.com/tidbcloud/metering/pkg/common/config"
	"gopkg.in/yaml.v3"
)

type Phase string

const (
	PreparePhase Phase = "prepare"
	RepushPhase  Phase = "repush"
)

type ReporterType string

const (
	OldReporter ReporterType = "old"
	V1Reporter  ReporterType = "v1"
	V2Reporter  ReporterType = "v2"
)

const (
	MeteringTypeInstance = "instance"
	MeteringTypeNetwork  = "network"
)

type SupplementaryConfig struct {
	SourceMysql  string           `json:"sourceMysql" yaml:"sourceMysql"`
	SourceObject SourceObjectType `json:"sourceObject" yaml:"sourceObject"`
	SourceFile   string           `json:"sourceFile" yaml:"sourceFile"`
	DestSQS      string           `json:"dest" yaml:"dest"`
	MeteringType string           `json:"meteringType" yaml:"meteringType"`
	ReporterType ReporterType     `json:"reporterType" yaml:"reporterType"`
	Phase        Phase            `json:"phase" yaml:"phase"`
	TenantIDs    []string         `json:"tenantIDs" yaml:"tenantIDs"`
	StartTime    int64            `json:"startTime" yaml:"startTime"`
	EndTime      int64            `json:"endTime" yaml:"endTime"`
	BatchSize    int64            `json:"batchSize" yaml:"batchSize"`
	Vendor       string           `json:"vendor" yaml:"vendor"`
	Env          string           `json:"env" yaml:"env"`
}

type SourceObjectType struct {
	AWS   config.StoreProviderAWSConfig   `json:"aws" yaml:"aws"`
	Azure config.StoreProviderAzureConfig `json:"azure" yaml:"azure"`
	GCP   config.StoreProviderGCPConfig   `json:"gcp" yaml:"gcp"`
}

func LoadConfig(path string) (*SupplementaryConfig, error) {
	var config SupplementaryConfig
	in, err := os.ReadFile(path)
	if err != nil {
		return nil, err
	}
	err = yaml.Unmarshal(in, &config)
	if err != nil {
		return nil, err
	}
	return &config, nil
}
