package cloudconfig

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

type ListDefaultConfigurationChangesReq struct {
	api.PaginationReq `json:",inline"`

	ContainItemType *ccent.DefaultConfigurationChangeItemType `form:"contain_item_type"`
}

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

	Changes []*ccent.DefaultConfigurationChange `json:"items"`
	Total   int64                               `json:"total"`
}

type GetDefaultConfigurationChangeReq struct {
	WithChangeItems bool `form:"with_change_items"`
}

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

	Change      *ccent.DefaultConfigurationChange                                                    `json:"change"`
	ChangeItems map[ccent.DefaultConfigurationChangeItemType][]*ccent.DefaultConfigurationChangeItem `json:"change_items"`
}

type UpdateTemplateDefaultCaseBindingByOpReq struct {
	Reason             string                            `json:"reason"`
	DefaultCaseBinding *ccent.TemplateDefaultCaseBinding `json:"default_case_bindings"`
}

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

	InstanceID uint64 `json:"instance_id"`
}

type DeleteTemplateDefaultCaseBindingByOpReq struct {
	Reason             string                            `json:"reason"`
	DefaultCaseBinding *ccent.TemplateDefaultCaseBinding `json:"default_case_bindings"`
}

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

	InstanceID uint64 `json:"instance_id"`
}

type ChangeTemplateDefaultCaseBindingsReq struct {
	Reason              string                              `json:"reason"`
	DefaultCaseBindings []*ccent.TemplateDefaultCaseBinding `json:"default_case_bindings"`
}

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

	ChangeID *uint64 `json:"change_id"`
}

type DiffDefaultConfigurationReleaseReq struct {
	Environment string `form:"environment" binding:"required"`
}

type DiffDefaultConfigurationReleaseResp struct {
	Different            bool                                      `json:"different"`
	UnreleasedBindings   []*ccent.TemplateDefaultCaseBindingChange `json:"unreleased_bindings"`
	UnreleasedComponents []*ccent.DefaultComponentConfigChange     `json:"unreleased_components"`
}

type CloseDefaultConfigurationChangeReq struct {
	Result ccent.DefaultConfigurationChangePhase `json:"result"`
	Reason string                                `json:"reason"`
}

type UpdateDefaultComponentsReq struct {
	Components []*ccent.DefaultComponentConfig `json:"components"`
}

type ChangeDefaultComponentsReq struct {
	Reason     string                          `json:"reason"`
	Components []*ccent.DefaultComponentConfig `json:"components"`
}

type ListDefaultVersionRulesReq struct {
	ClusterType ccent.ClusterType `form:"cluster_type" json:"cluster_type" binding:"required"`
	Component   string            `form:"component" json:"component"`
}

type DefaultVersionRule struct {
	ClusterType    ccent.ClusterType `json:"cluster_type"`
	Component      string            `json:"component"`
	ClusterVersion string            `json:"cluster_version"`
	CloudProvider  string            `json:"cloud_provider"`
	Region         string            `json:"region"`
	Version        string            `json:"version"`
}

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

	Rules []*DefaultVersionRule `json:"rules"`
}

type ReleaseVersionReq struct {
	ClusterType   ccent.ClusterType `json:"cluster_type"`
	SourceVersion string            `json:"source_version"`
	TargetVersion string            `json:"target_version"`
}

type ImportVersionsReq struct {
	MinVersion   string `json:"min_version"`
	MaxVersion   string `json:"max_version"`
	GitopsBranch string `json:"gitops_branch"`
	TierBranch   string `json:"tier_branch"`
	Reason       string `json:"reason"`
}

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

	InstanceID uint64 `json:"instance_id"`
}
