package model

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

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

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

type AzureBlobStorageRequirement struct {
	AzureBlobStorageDimensions
}

func (t *AzureBlobStorageRequirement) Type() string {
	return AzureBlobStorage
}

func (t *AzureBlobStorageRequirement) IsDedicated() bool {
	// Notice: we don't support dedicated azure storage account for a specific case
	return false
}

type AzureBlobStorageEntity struct {
	CreatedByDriver            bool
	AzureBlobStorageDimensions `yaml:",inline"`
	SASToken                   string `yaml:"sasToken"`
	ContainerURI               string `yaml:"containerURI"`
}

func (t *AzureBlobStorageEntity) Type() string {
	return AzureBlobStorage
}
func (t *AzureBlobStorageEntity) IsCreatedByDriver() bool {
	return t.CreatedByDriver
}

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

type AzureBlobStorageEntities []*AzureBlobStorageEntity

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