package model

import (
	"github.com/tidbcloud/dataflow-service-e2e/internal/misc"
	"gopkg.in/yaml.v2"
)

type S3Dimensions struct {
	Region string `yaml:"region"`
}

func (t S3Dimensions) Dimensions() map[string]string {
	return misc.StructToMap(t)
}

type S3Requirement struct {
	S3Dimensions
}

func (t *S3Requirement) Type() string {
	return S3
}

func (t *S3Requirement) IsDedicated() bool {
	// Notice: we don't support dedicated mysql a specific case
	return false
}

type S3Entity struct {
	CreatedByDriver bool
	S3Dimensions    `yaml:",inline"`
	AccessKey       string `yaml:"accessKey"`
	SecretKey       string `yaml:"secretKey"`
	RoleARN         string `yaml:"roleARN"`
	BucketURI       string `yaml:"bucketURI"`
}

func (t *S3Entity) Type() string {
	return S3
}
func (t *S3Entity) IsCreatedByDriver() bool {
	return t.CreatedByDriver
}

func (t *S3Entity) UsesAssumeRole() bool {
	return t.RoleARN != ""
}

func (t *S3Entity) Copy() *S3Entity {
	data, err := yaml.Marshal(t)
	if err != nil {
		panic(err)
	}
	var copied S3Entity
	err = yaml.Unmarshal(data, &copied)
	return &copied
}

type S3Entities []*S3Entity

func (t S3Entities) ToDependencyEntities() []DependencyEntity {
	var entities []DependencyEntity
	for _, it := range t {
		entities = append(entities, it)
	}
	return entities
}
