package cloudconfig

import "fmt"

type TemplateDefaultCase struct {
	CloudInstanceType `json:",inline"`
	Version           string `json:"version"`
	Region            string `json:"region"`
	ConfigType        string `json:"config_type"`
	TenantID          string `json:"tenant_id"`
} // @name cloudconfig.TemplateDefaultCase

func (c TemplateDefaultCase) IsEqual(tc TemplateDefaultCase) bool {
	return c.CloudInstanceType == tc.CloudInstanceType &&
		c.Version == tc.Version &&
		c.ConfigType == tc.ConfigType &&
		c.Region == tc.Region &&
		c.TenantID == tc.TenantID
}

func (c TemplateDefaultCase) HumanReadString() string {
	return fmt.Sprintf("%s:%s:%s:%s:%s", c.Version, c.ConfigType, c.CloudInstanceType.CloudProvider, c.CloudInstanceType.InstanceType, c.TenantID)
}

type Template struct {
	ID                 uint64                     `json:"id"` // id in the config center
	Name               string                     `json:"name"`
	ClusterType        ClusterType                `json:"cluster_type"`
	ConfigType         string                     `json:"config_type"`
	Tags               map[string]string          `json:"tags"`
	Parameters         map[string]*NamedParameter `json:"parameters"` // key: parameter name
	CustomTemplateInfo CustomTemplateInfo         `json:"custom_template_info"`
	// Output only
	DefaultCases []*TemplateDefaultCase `json:"default_cases"`
}

type CustomTemplateInfo struct {
	Data map[string]Template `json:"data"` // key: config_type
}

type TemplateDefaultCaseBinding struct {
	DefaultCase TemplateDefaultCase `json:"default_case"`
	ClusterType ClusterType         `json:"cluster_type"`
	TemplateID  uint64              `json:"template_id"`
}

type ComponentDefaultCase struct {
	ClusterType ClusterType `json:"cluster_type"`
	Component   string      `json:"component"`
	Version     string      `json:"version"`
} // @name cloudconfig.ComponentDefaultCase

func (c ComponentDefaultCase) IsEqual(tc ComponentDefaultCase) bool {
	return c.ClusterType == tc.ClusterType &&
		c.Version == tc.Version &&
		c.Component == tc.Component
}
func (c ComponentDefaultCase) HumanReadString() string {
	return fmt.Sprintf("%s:%s:%s", c.ClusterType, c.Component, c.Version)
}

type DefaultComponentConfig struct {
	DefaultCase ComponentDefaultCase `json:"default_case"`
	BaseImage   string               `json:"base_image"`
	ImageTag    string               `json:"image_tag"`
} // @name cloudconfig.DefaultComponentConfiguration
