package cloudconfig

import (
	"github.com/tidbcloud/devops/api"
	ccent "github.com/tidbcloud/devops/entity/cloudconfig"
	opent "github.com/tidbcloud/devops/entity/operation"
)

type ClusterConfigurationLocator struct {
	ClusterType ccent.ClusterType `form:"cluster_type" binding:"required" json:"cluster_type"`
	ClusterID   string            `form:"cluster_id" binding:"required" json:"cluster_id"`
} // @name cloudconfig.ClusterConfigurationLocator

type TenantInitConfigurationLocator struct {
	ClusterType ccent.ClusterType `form:"cluster_type" binding:"required" json:"cluster_type"`
	TenantID    string            `form:"tenant_id" binding:"required" json:"tenant_id"`
} // @name cloudconfig.TenantInitConfigurationLocator

type ConfigurationTemplateLocator struct {
	ClusterType  ccent.ClusterType  `form:"cluster_type" binding:"required" json:"cluster_type"`
	TemplateType ccent.TemplateType `form:"template_type" binding:"required" json:"template_type"`
	TenantID     *string            `form:"tenant_id" json:"tenant_id,omitempty"` // Own Tenant ID, only for TemplateTypeTenantDefault
} // @name cloudconfig.ConfigurationTemplateLocator

type ListConfigurationChangeReq struct {
	api.PaginationReq
	IDOnly                    bool   `form:"id_only" json:"id_only"`
	HaveModifiedParameterLike string `form:"have_modified_param_like" json:"have_modified_param_like"`
}

type ConfigurationChangeable struct {
	Changeable bool   `json:"changeable"`
	Reason     string `json:"reason"`
}

type ListConfigTypesResp struct {
	ConfigTypes []string `json:"config_types"`
}

type ListComponentsResp struct {
	Components []string `json:"components"`
}

type ComponentInfo struct {
	ComponentName       string `json:"component_name"`
	Version             string `json:"version"`
	BaseImage           string `json:"base_image"`
	ImageTag            string `json:"image_tag"`
	GeneralAvailability bool   `json:"general_availability"`
}

type UpdateComponentImageReq struct {
	ClusterType ccent.ClusterType       `json:"cluster_type"`
	Version     string                  `json:"version"`
	BaseImage   string                  `json:"base_image"`
	Tag         string                  `json:"tag"`
	Policy      opent.ActionStartPolicy `json:"policy"`
	Author      string                  `json:"author" binding:"omitempty,email"`
	ReleaseID   string                  `json:"release_id"`
	ChangeID    string                  `json:"change_id"`
}

type ListComponentImageUpdateRecordsReq struct {
	api.PaginationReq

	ClusterType ccent.ClusterType `form:"cluster_type" json:"cluster_type"`
}

type ListComponentImageUpdateRecordsResp struct {
	api.BaseResp `json:",inline"`

	Total     int64             `json:"total"`
	Instances []*opent.Instance `json:"items"`
}

type ListAvailableComponentVersionsResp struct {
	Versions []string        `json:"versions"`
	Detail   []ComponentInfo `json:"detail"`
}

type ListInstanceTypesResp struct {
	InstanceTypes []*ccent.CloudInstanceType `json:"instance_types"`
}

type ListAvailableClusterVersionsResp struct {
	Versions []*ccent.AvailableClusterVersion `json:"items"`
}

type UpdateDefaultClusterVersionReq struct {
	IsDefault bool `json:"is_default"`
}

type UpdateDefaultClusterVersionResp struct {
	api.BaseResp `json:",inline"`

	InstanceID uint64 `json:"instance_id"`
}

type GetConfigurationResp struct {
	api.BaseResp `json:",inline"`

	Configuration *ccent.Configuration     `json:"configuration"`
	Changeable    *ConfigurationChangeable `json:"changeable"`
	InitVersion   *ccent.TenantVersions    `json:"default_version"`
}

type ListAvailableComponentVersionsReq struct {
	TenantID string `form:"tenant_id" json:"tenant_id"`
}

type SearchClusterComponentsReq struct {
	Page             int32             `form:"page,default=1" binding:"gt=0" json:"page"`
	PerPage          int32             `form:"per_page,default=100" binding:"gt=0,lte=500" json:"per_page"`
	TenantID         string            `form:"tenant_id" json:"tenant_id"`
	ClusterID        string            `form:"cluster_id" json:"cluster_id"`
	ClusterType      ccent.ClusterType `form:"cluster_type" binding:"required" json:"cluster_type"`
	ComponentName    string            `form:"component_name" json:"component_name"`
	ComponentVersion string            `form:"component_version" json:"component_version"`
	ImageTag         string            `form:"image_tag" json:"image_tag"`
	LogicalRegion    string            `form:"logical_region" json:"logical_region"`
	RegionMode       string            `form:"region_mode" json:"region_mode"`
} // @name cloudconfig.SearchClusterComponentsReq

type SearchClusterComponentsResp struct {
	api.BaseResp `json:",inline"`

	Total          int64                                       `json:"total"`
	Items          []*ccent.ClusterComponentVersion            `json:"items"`
	RegionResults  []*ccent.ClusterComponentSearchRegionResult `json:"region_results,omitempty"`
	PartialFailure bool                                        `json:"partial_failure"`
} // @name cloudconfig.SearchClusterComponentsResp
