package operation

type (
	ParamName  string
	OutputName string
)

const (
	// /////////////
	// ParamName
	// /////////////
	// All params must match the operation definition.
	// Ref: https://github.com/tidbcloud/app-delivery/blob/main/devops-server/envs/dev/operations.yaml
	ParamClusterID                ParamName = "cluster_id"                  // value: uint64
	ParamProjectID                ParamName = "project_id"                  // value: uint64
	ParamTenantID                 ParamName = "tenant_id"                   // value: uint64
	ParamTenantRegion             ParamName = "tenant_region"               // value: TenantRegion or ParamTenantRegionSharedPool
	ParamOncallCategory           ParamName = "oncall_category"             // value: string
	ParamPlaneType                ParamName = "plane_type"                  // value: string, ex: control_plane, data_plane
	ParamClusterComponentsToScale ParamName = "cluster_components_to_scale" // value: ClusterComponentsToScale, used by scale cluster
	ParamTiDBNodeQuota            ParamName = "tidb_node_quota"             // value: int, used by update tenant quota
	ParamTiKVNodeQuota            ParamName = "tikv_node_quota"             // value: int, used by update tenant quota
	ParamTiFlashNodeQuota         ParamName = "tiflash_node_quota"          // value: int, used by update tenant quota
	ParamTiProxyNodeQuota         ParamName = "tiproxy_node_quota"          // value: int, used by update tenant quota
	ParamJumpAuthorizationID      ParamName = "jump_auth_id"                // value: uint64
	ParamConfigurationChangeID    ParamName = "configuration_change_id"     // value: uint64
	ParamConfigChangeID           ParamName = "change_id"                   // value: uint64 config change ID
	ParamForceRestart             ParamName = "force_restart"               // value: string
	ParamRestartTarget            ParamName = "restart_target"              // value: string
	ParamRestartTargetType        ParamName = "restart_target_type"         // value: string
	ParamForce                    ParamName = "force"                       // value: string, do operation without status check
	ParamDryRun                   ParamName = "dry_run"                     // value: string
	ParamEnabled                  ParamName = "enabled"                     // value: string
	ParamSampleRate               ParamName = "sample_rate"                 // value: string
	ParamOptionalMode             ParamName = "optional_mode"               // value: string
	ParamOptionalFields           ParamName = "optional_fields"             // value: string
	ParamAggregationInterval      ParamName = "aggregation_interval"        // value: string
	ParamMetadataMode             ParamName = "metadata_mode"               // value: string
	ParamMetadataFields           ParamName = "metadata_fields"             // value: string
	ParamNamespace                ParamName = "namespace"
	ParamRestartScope             ParamName = "restart_scope" // value: "namespace" | "cluster", used by ServerlessOpsRestartTiDBPods
	ParamKubernetes               ParamName = "kubernetes"    // value: string, EKS/GKE cluster name. Used by pool-level serverless ops that do not tie to a tenant cluster.
	ParamRegion                   ParamName = "region"
	ParamJobID                    ParamName = "job_id"
	ParamComponentType            ParamName = "component_type"
	ParamComponentID              ParamName = "component_id"
	ParamNodeSize                 ParamName = "node_size"
	ParamReplicas                 ParamName = "replicas"
	ParamOperationType            ParamName = "operation_type"
	ParamMemberName               ParamName = "member_name"
	ParamPodName                  ParamName = "pod_name"
	ParamInstanceID               ParamName = "instance_id"
	ParamDesiredVersion           ParamName = "desired_version"
	ParamAvailabilityZone         ParamName = "availability_zone" // value: string, e.g. us-east-1a
	ParamGracefulTimeout          ParamName = "graceful_timeout"  // value: duration string, e.g. 5m
	ParamGroupIDs                 ParamName = "group_ids"         // value: comma-separated TiDB group IDs
	ParamExpiresIn                ParamName = "expires_in"        // value: AWS ARC duration, e.g. 72h
	ParamWaitDuration             ParamName = "wait_duration"     // value: duration string, e.g. 30m

	ParamTenantEmail                     ParamName = "tenant_email"                        // value: string
	ParamTenantStatus                    ParamName = "tenant_status"                       // value: string
	ParamTenantType                      ParamName = "tenant_type"                         // value: string
	ParamTenantThirdPartyAccountCode     ParamName = "tenant_third_party_account_code"     // value: string
	ParamTenantThirdPartyAccountProvider ParamName = "tenant_third_party_account_provider" // value: string
	ParamTenantThirdPartyFreeTrial       ParamName = "tenant_third_party_free_trial"       // value: string
	ParamUserID                          ParamName = "user_id"                             // value: string
	ParamUserEmail                       ParamName = "user_email"                          // value: string
	ParamUserRole                        ParamName = "user_role"                           // value: string
	ParamSalesOwner                      ParamName = "sales_owner"                         // value: string

	// ng params
	ParamTiDBGroupID           ParamName = "tidb_group_id"  // value: string
	ParamTiKVGroupID           ParamName = "tikv_group_id"  // value: string
	ParamNodeCount             ParamName = "node_count"     // value: int
	ParamCpuCores              ParamName = "cpu_cores"      // value: int
	ParamMemoryGi              ParamName = "memory_gi"      // value: int
	ParamImage                 ParamName = "image"          // value: string
	ParamExclusive             ParamName = "exclusive"      // value: bool
	ParamForceCreate           ParamName = "force_create"   // value: bool
	ParamForceReplace          ParamName = "force_replace"  // value: bool
	ParamBackupRetentionDays   ParamName = "retention_days" // value: int, 1 to 33 for the internal flexible-backup override
	ParamBackupRetentionReason ParamName = "reason"         // value: non-empty string

	ParamExternalDNSEnable ParamName = "enable" // value: string ("true"/"false")
	ParamTTL               ParamName = "ttl"    // value: int
	// ParamScaleDirection is computed by PreCheck for ng scale operations: "up", "down", or "mixed".
	// Used by the approval condition to require TSE review only when scaling down.
	ParamScaleDirection     ParamName = "scale_direction"      // value: "up" | "down" | "mixed"
	ParamVolumeName         ParamName = "volume_name"          // value: string
	ParamRestartTargetGroup ParamName = "restart_target_group" // value: string
	ParamLabels             ParamName = "labels"               // value: map[string]string, JSON encoded

	// Data Synchronization
	ParamSourceClusterID       ParamName = "source_cluster_id"       // value: uint64
	ParamTargetClusterID       ParamName = "target_cluster_id"       // value: uint64
	ParamTargetTiDBGroupID     ParamName = "target_tidb_group_id"    // value: uint64
	ParamDataSyncName          ParamName = "data_sync_name"          // value: string
	ParamDataSyncDescription   ParamName = "data_sync_description"   // value: string
	ParamDataSyncRCU           ParamName = "data_sync_rcu"           // value: uint64
	ParamDataSyncStartTSO      ParamName = "data_sync_start_tso"     // value: string
	ParamTargetClusterUsername ParamName = "target_cluster_username" // value: string
	ParamTargetClusterPassword ParamName = "target_cluster_password" // value: string
	ParamMaxNodeCount          ParamName = "max_node_count"
	ParamMinNodeCount          ParamName = "min_node_count"
	ParamScaleUpEnabled        ParamName = "scale_up_enabled"   // value: string ("true"/"false")
	ParamScaleDownEnabled      ParamName = "scale_down_enabled" // value: string ("true"/"false")

	// credits approval params
	ParamDepartment      ParamName = "department"
	ParamTotalCredits    ParamName = "total_credits"
	ParamExpiredDate     ParamName = "expired_date"
	ParamUsage           ParamName = "usage"
	ParamUnitFilters     ParamName = "unit_filters"
	ParamDiscountEnabled ParamName = "discount_enabled"
	ParamApplyForTest    ParamName = "apply_for_test"

	// bills recalculate approval params
	ParamBillingConfigID        ParamName = "billing_config_id"
	ParamInvoiceID              ParamName = "invoice_id"
	ParamSourceRunID            ParamName = "source_run_id"
	ParamOverwriteCurrentCost   ParamName = "overwrite_current_cost"
	ParamCreditsTotalCredits    ParamName = "credits_total_credits"
	ParamCreditsDiscountEnabled ParamName = "credits_discount_enabled"
	ParamCreditsExpiredDate     ParamName = "credits_expired_date"
	ParamCreditsProvider        ParamName = "credits_provider"
	ParamCreditsStartDate       ParamName = "credits_start_date"
	ParamCreditsUnitFilters     ParamName = "credits_unit_filters" // #nosec G101 -- operation parameter name, not a credential.

	// Ops Param
	ParamCloudConfigVersion                             ParamName = "version"
	ParamCloudConfigClusterType                         ParamName = "cluster_type"
	ParamCloudConfigClusterVersion                      ParamName = "cluster_version"
	ParamCloudConfigUpdateDefaultTemplateBindingRequest ParamName = "update_default_template_binding_request"
	ParamCloudConfigDeleteDefaultTemplateBindingRequest ParamName = "delete_default_template_binding_request"

	ParamUseCase ParamName = "use_case"

	ParamTiDBCloudInstance  ParamName = "tidb_cloud_instance"
	ParamProvider           ParamName = "cloud_provider"
	ParamCloudAccountID     ParamName = "cloud_account_id"
	ParamRegionName         ParamName = "region_name"
	ParamLogicalRegionName  ParamName = "logical_region_name"
	ParamO11YRegionName     ParamName = "o11y_region_name"
	ParamSPUsCollectionName ParamName = "spus_collection_name"
	ParamSKUCollectionName  ParamName = "sku_collection_name"
	ParamMAccount           ParamName = "m_account"
	ParamDAccount           ParamName = "d_account"
	ParamDAccounts          ParamName = "d_accounts"
	ParamO11YAccount        ParamName = "o11y_account"

	ParamVolumeIops           ParamName = "volume_iops"
	ParamAdditionalVolumeIops ParamName = "volume_additional_iops"
	ParamVolumeSize           ParamName = "volume_size"
	ParamVolumeThroughput     ParamName = "volume_throughput"
	ParamVolumeSizeGi         ParamName = "volume_size_gi"
	ParamVolumeThroughputMbs  ParamName = "volume_throughput_mbs"
	ParamForceModify          ParamName = "force_modify"
	ParamStorageType          ParamName = "storage_type"
	ParamVolumeType           ParamName = "volume_type"
	ParamForceScale           ParamName = "force_scale"

	// Spu, Sku update
	ParamPatchSpuID   ParamName = "spu_id"
	ParamPatchSkuID   ParamName = "sku_id"
	ParamPatchSpuBody ParamName = "patch_spu_body"
	ParamPatchSpuInfo ParamName = "patch_spu_info"
	ParamPatchSkuBody ParamName = "patch_sku_body"
	ParamPatchSkuInfo ParamName = "patch_sku_info"

	// serverless cluster
	ParamMinTiDBReplicas ParamName = "min_tidb_replicas"
	ParamMaxTiDBReplicas ParamName = "max_tidb_replicas"
	ParamMinRCU          ParamName = "min_rcu"
	ParamMaxRCU          ParamName = "max_rcu"
	ParamTiDBPool        ParamName = "tidb_pool"
	ParamRUMode          ParamName = "ru_mode"
	ParamCanary          ParamName = "canary"

	// vpc cidr
	ParamVPCID         ParamName = "vpc_id"
	ParamSecondaryCIDR ParamName = "secondary_cidr"

	// cluster migration
	ParamCreateMigrationClusterRequest    ParamName = "create_migration_cluster_request"    // value: string (json marshal)
	ParamMigratePrivateLinkRequest        ParamName = "migrate_privatelink_request"         // value: string (json marshal)
	ParamApplyHeterogeneousDeployRequest  ParamName = "apply_heterogeneous_deploy_request"  // value: string (json marshal)
	ParamDeleteHeterogeneousDeployRequest ParamName = "delete_heterogeneous_deploy_request" // value: string (json marshal)

	// /////////////
	// OutputName
	// /////////////
	OutputPausedTCNames                         OutputName = "paused_tc_names"    // value: string
	OutputResumedTCNames                        OutputName = "resumed_tc_names"   // value: string
	OutputDeletedASTSNames                      OutputName = "deleted_asts_names" // value: string
	OutputConfigRevisionID                      OutputName = "config_revision_id" // value: string
	OutputScaleClusterID                        OutputName = "scale_cluster_id"   // value: string
	OutputOperateClusterID                      OutputName = "operate_cluster_id" // value: string
	OutputOperationID                           OutputName = "operation_id"       // value: string
	OutputOperationIDStartZonalShift            OutputName = "operation_id_start_zonal_shift"
	OutputOperationIDOfflineAZ                  OutputName = "operation_id_offline_az"
	OutputOperationIDRecoverAZ                  OutputName = "operation_id_recover_az"
	OutputOperationIDStopZonalShift             OutputName = "operation_id_stop_zonal_shift"
	OutputOperationArgs                         OutputName = "operation_args" // value: string
	OutputRegion                                OutputName = "region"
	OutputCloudProvider                         OutputName = "cloud_provider"
	OutputNodeGroupNames                        OutputName = "nodegroup_names"
	OutputDesiredVersion                        OutputName = "desired_version"
	OutputPrivateLinkMigrationID                OutputName = "privatelink_migration_id"
	OutputPrivateLinkMigrationTargetServicePlan OutputName = "privatelink_migration_target_service_plan"
	OutputClusterMigrationID                    OutputName = "cluster_migration_id"
	OutputTargetClusterID                       OutputName = "target_cluster_id"
	OutputTargetClusterDisplayName              OutputName = "target_cluster_display_name"
	OutputTrafficReplayID                       OutputName = "traffic_replay_id"
	OutputDataSynchronizationID                 OutputName = "data_synchronization_id"
	OutputPlacementPolicyID                     OutputName = "placement_policy_id"

	// /////////////
	// NextGen Region
	// /////////////
	ParamRdsName           ParamName = "rds_name"           // value: string, the name of the RDS instance for NextGen region
	ParamCreateRds         ParamName = "create_rds"         // value: string, Whether to create RDS instance for NextGen region
	ParamAvailabilityZones ParamName = "availability_zones" // value: string, the availability zones of the NextGen region

	// /////////////
	// NextGen Modify Component Image
	// /////////////
	ParamNgModifyImageComponent         ParamName = "component"           // value: string, the component to modify image
	ParamNgModifyImageBaseImage         ParamName = "base_image"          // value: string, the base image
	ParamNgModifyImageTag               ParamName = "tag"                 // value: string, the tag
	ParamNgModifyImageRelatedChangeLink ParamName = "related_change_link" // value: string, the related change link

	// /////////////
	// Kernel Image Delivery
	// /////////////
	ParamKernelImageArtifactUID           ParamName = "artifact_uid"
	ParamKernelImageLocalDevOpsEnv        ParamName = "local_devops_environment"
	ParamKernelImageSourceRepository      ParamName = "source_repository"
	ParamKernelImageSourceTag             ParamName = "source_tag"
	ParamKernelImageDeliveryCorrelationID ParamName = "delivery_correlation_id"

	// /////////////
	// Region
	// /////////////
	ParamRegionDeployType           ParamName = "region_deploy_type"
	ParamRegisterRegionRequest      ParamName = "register_region_request"
	ParamUpdateRegionRequest        ParamName = "update_region_request"
	ParamUpdateRegionRequestChanged ParamName = "update_region_request_changed"
	// /////////////
	// BYOC Region
	// /////////////
	ParamPCAArn                                ParamName = "pca_arn"               // value: string, the ARN of the PCA role for BYOC region
	ParamTidbHostedZoneName                    ParamName = "tidb_hosted_zone_name" // value: string, the hosted zone name for TiDB Cloud DNS
	ParamO11yHostedZoneName                    ParamName = "o11y_hosted_zone_name" // value: string, the hosted zone name for O11Y DNS
	ParamECR                                   ParamName = "ecr"                   // value: string, the ECR repository for BYOC region
	ParamUpdateRegionOpsAuditLogSettingRequest ParamName = "update_region_ops_audit_log_setting_request"

	// /////////////
	// CDC Operation
	// /////////////
	ParamCDCClusterID            ParamName = "ticdc_cluster_id"
	ParamChangefeedID            ParamName = "changefeed_id"
	ParamCDCOperationClusterType ParamName = "cluster_type"
	// ParamCDCAPIVersion ParamName = "cdc_api_version" // value: string, ex: v1, v2
	// ParamTCName        ParamName = "tc_name"
	// ParamClusterName   ParamName = "cluster_name" // value: string, the name of the TiDB Cloud cluster

	// Resource Pool
	ParamCIDR                      ParamName = "cidr"                        // value: string
	ParamServicePlan               ParamName = "service_plan"                // value: string, ex: Starter, Essential, Premium, BYOC
	ParamInstanceMaxRCU            ParamName = "instanceMaxRCU"              // value: uint64
	ParamTotalMaxRCU               ParamName = "totalMaxRCU"                 // value: uint64
	ParamBurstyRatio               ParamName = "burstyRatio"                 // value: float
	ParamIdleResourcePoolTTLInHour ParamName = "idleResourcePoolTtlInHours"  // value: uint64
	ParamMinimalRCUBaseline        ParamName = "minimalRcuBaseline"          // value: uint64
	ParamMinimalRCUCoefficient     ParamName = "minimalRcuCoefficient"       // value: float
	ParamScaleDownCooldownMinutes  ParamName = "scaleDownCooldownMinutes"    // value: uint64, cooldown in minutes after capacity change before scale-down is allowed
	ParamInitialRcu                ParamName = "initial_rcu"                 // value: uint32
	ParamResourcePoolID            ParamName = "resource_pool_id"            // value: uint64
	ParamInstanceLimit             ParamName = "instance_limit"              // value: uint64
	ParamVcpusLimit                ParamName = "vcpus_limit"                 // value: uint64
	ParamVcpusLimitPerResourcePool ParamName = "vcpusLimitPerResourcePool"   // value: uint64
	ParamK8SServiceCIDR            ParamName = "k8s_service_cidr"            // value: string
	ParamMetaProfileID             ParamName = "meta_profile_id"             // value: string
	ParamProviderIdentity          ParamName = "provider_identity"           // value: string
	ParamEnableCapacityPlanner     ParamName = "enable_capacity_planner"     // value: bool
	ParamPlacementGroupEnabled     ParamName = "placement_group_enabled"     // value: bool
	ParamPdDeploymentMode          ParamName = "pd_deployment_mode"          // value: MICROSERVICE or MONOLITHIC
	ParamHighAvailabilityType      ParamName = "high_availability_type"      // value: REGIONAL or ZONAL
	ParamNodeZones                 ParamName = "node_zones"                  // value: comma-separated zone names, e.g. us-west-2a,us-west-2b,us-west-2c
	ParamEnabledTiKVRemoteWorkers  ParamName = "enabled_tikv_remote_workers" // value: TIKV_WORKER,COPROCESSOR_WORKER or TIKV_WORKER
	ParamTiflashMode               ParamName = "tiflash_mode"                // value: AUTO, LEGACY, or COLUMNAR
	ParamLogicalRegion             ParamName = "logical_region"              // value: string, only effective for Essential_V2

	ParamCreateManualBackupBeforePause ParamName = "create_manual_backup_before_pause" // value: bool

	// VPC Peering
	ParamCreateVPCPeeringRequest ParamName = "create_vpc_peering_request"
	ParamVPCPeeringID            ParamName = "vpc_peering_id" // value: string

	// Meta Profile
	ParamMetaProfifleCreateRequest ParamName = "create_meta_profile_request"

	// Traffic Mirror
	ParamTrafficReplayID                   ParamName = "traffic_replay_id"
	ParamCreateTrafficReplayRequest        ParamName = "create_traffic_replay_request"
	ParamUpdateTrafficReplayRequest        ParamName = "update_traffic_replay_request"
	ParamUpdateTrafficReplayRequestChanged ParamName = "update_traffic_replay_request_changed"
	ParamStartTrafficReplayRequest         ParamName = "start_traffic_replay_request"
	ParamStopTrafficReplayRequest          ParamName = "stop_traffic_replay_request"
	ParamDeleteTrafficReplayRequest        ParamName = "delete_traffic_replay_request"

	// Reserved Capacity Template
	ParamCreateReservedCapacityTemplateRequest       ParamName = "create_reserved_capacity_template_request"
	ParamUpdateReservedCapacityTemplateStatusRequest ParamName = "update_reserved_capacity_template_status_request"
	ParamDeleteReservedCapacityTemplateRequest       ParamName = "delete_reserved_capacity_template_request"
)

const (
	// ParamTenantRegionSharedPool marks shared resource-pool operations that have no owning tenant.
	ParamTenantRegionSharedPool = "SHARED_POOL"
)

type ParamType string

const (
	ParamTypeString ParamType = "string"
	ParamTypeInt    ParamType = "int"
	// ParamTypeMap represents a map[string]string parameter, stored as JSON.
	ParamTypeMap ParamType = "map"
)

var (
	ParamTypeValues = []ParamType{ParamTypeString, ParamTypeInt, ParamTypeMap}
)

// ParamDefine determine how this param is shown in UI.
type ParamDefine struct {
	Type ParamType `json:"type" yaml:"type"`
	// Description is the description of the param.
	Desc string `json:"desc,omitempty" yaml:"desc,omitempty"`
	// Optional is whether this param is optional.
	Optional bool `json:"optional,omitempty" yaml:"optional,omitempty"`

	// Default is the default value of the param.
	Default *string `json:"default,omitempty" yaml:"default,omitempty"`
	// Enum is the enum value of the param.
	Enum []string `json:"enum,omitempty" yaml:"enum,omitempty"`
	// MultiEnum is the multi enum value of the param.
	MultiEnum []string `json:"multi_enum,omitempty" yaml:"multiEnum,omitempty"`
	// Const is the const value of the param.
	Const *string `json:"const,omitempty" yaml:"const"`
}

func (p ParamDefine) IsConstValue() (string, bool) {
	if p.Const == nil {
		return "", false
	}
	return *p.Const, true
}
