package cloudconfig

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

type ChangeVersionReq struct {
	ToVersion string `json:"to_version"`
}

type ChangeTemplateReq struct {
	ToTemplateID uint64 `json:"to_template"`
}

type ChangeImageTagReq struct {
	ToImageTag string `json:"to_image_tag"`
}

type ChangeFileReq struct {
	Filename         string                  `json:"filename"`
	ConfigType       string                  `json:"config_type"`
	CustomParameters []*ccent.NamedParameter `json:"custom_parameters"`
	Template         *ChangeTemplateReq      `json:"template"`
	PreviousText     string                  `json:"previous_text"`
}

type ChangeComponentReq struct {
	Component         string             `json:"component"`
	OverwriteImageTag *ChangeImageTagReq `json:"overwrite_image_tag"`
	Version           *ChangeVersionReq  `json:"version"`
}

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

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

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

	Change *ccent.ConfigurationChange `json:"change"`
}

type CreateConfigurationChangeReq struct {
	Reason          string                                  `json:"reason"`
	ApplyPolicy     ccent.ParameterApplyPolicy              `json:"apply_policy"`
	Components      []*ChangeComponentReq                   `json:"components"`
	Files           []*ChangeFileReq                        `json:"files"`
	ChangeType      string                                  `json:"change_type"`
	Version         *ChangeVersionReq                       `json:"version"`
	ExecutionWindow *clusterapi.CreateOpsExecutionWindowReq `json:"execution_window"`
}

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

	ChangeID *uint64 `json:"change_id"`
}

type PreviewConfigurationChangeReq struct {
	Components []*ChangeComponentReq `json:"components"`
	Files      []*ChangeFileReq      `json:"files"`
	ChangeType string                `json:"change_type"`
	Version    *ChangeVersionReq     `json:"version"`
}

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

	Change        *ccent.ConfigurationChange   `json:"change"`
	Configuration *ccent.Configuration         `json:"configuration"`
	ApplyPolicies []ccent.ParameterApplyPolicy `json:"apply_policies"`
	Reason        string                       `json:"reasons"`
}

type ApplyMode struct {
	AllowMethods []string `json:"allow_methods"`
	DenyMethods  []string `json:"deny_methods"`
}

type ApplyConfigurationChangeReq struct {
	Mode *ApplyMode `json:"mode"`
}
