package cloudconfig

import "github.com/tidbcloud/devops/api"

// type ListInternalChangefeedsReq struct {
// 	TidbClusterId uint64 `form:"cluster_id"`
// }

type ListInternalChangefeedsResp struct {
	Changefeeds []*InternalChangefeed `json:"changefeeds"`
}

type GetInternalChangefeedResp struct {
	Changefeed *InternalChangefeed `json:"changefeed"`
}

type GetInternalTiCDCClusterResp struct {
	TiCDCCluster *InternalTiCDCCluster `json:"ticdc_cluster"`
}

type OperationResp struct {
	api.BaseResp

	InstanceID *uint64 `json:"instance_id"` // the operation instance id
}

type InternalChangefeed struct {
	Id               string                   `json:"id"`
	DisplayId        string                   `json:"display_id"`
	ClusterType      string                   `json:"cluster_type"`
	Arch             string                   `json:"arch,omitempty"`
	DisplayName      string                   `json:"display_name"`
	DownstreamType   string                   `json:"downstream_type"`
	Status           string                   `json:"status"`
	CreatedAt        int64                    `json:"created_at"` //timestamp
	TiCDCClusterName string                   `json:"ticdc_cluster_name,omitempty"`
	TicdcCluster     *InternalTiCDCCluster    `json:"ticdc_cluster"`
	NetworkInfo      *ChangefeedNetworkInfo   `json:"network_info,omitempty"`
	CheckpointTSO    string                   `json:"checkpoint_tso,omitempty"`
	CheckpointTS     int64                    `json:"checkpoint_ts,omitempty"`
	RCU              string                   `json:"rcu,omitempty"`
	TableConfig      *ChangefeedTableConfig   `json:"table_config,omitempty"`
	StartPosition    *ChangefeedStartPosition `json:"start_position,omitempty"`
	DownstreamConfig map[string]interface{}   `json:"downstream_config,omitempty"`
}

type ChangefeedNetworkInfo struct {
	NetworkType            string            `json:"network_type"`
	PrivateLinkServiceName string            `json:"private_link_service_name,omitempty"`
	KafkaID                string            `json:"kafka_id,omitempty"`
	Ports                  []uint32          `json:"ports,omitempty"`
	AdvertisedPatternGroup map[string]string `json:"advertised_pattern_group,omitempty"`
	SinkEndpointID         string            `json:"sink_endpoint_id,omitempty"`
}

type ChangefeedTableConfig struct {
	FilterRules   []string                 `json:"filter_rules"`
	Mode          string                   `json:"mode"`
	CaseSensitive bool                     `json:"case_sensitive"`
	EventFilters  []*ChangefeedEventFilter `json:"event_filters"`
}

type ChangefeedEventFilter struct {
	TableMatchers                   []string `json:"table_matchers"`
	IgnoredEvents                   []string `json:"ignored_events"`
	IgnoredSQLStatements            []string `json:"ignored_sql_statements"`
	IgnoredInsertValueExpression    string   `json:"ignored_insert_value_expression,omitempty"`
	IgnoredUpdateNewValueExpression string   `json:"ignored_update_new_value_expression,omitempty"`
	IgnoredUpdateOldValueExpression string   `json:"ignored_update_old_value_expression,omitempty"`
	IgnoredDeleteValueExpression    string   `json:"ignored_delete_value_expression,omitempty"`
}

type ChangefeedStartPosition struct {
	Mode      string `json:"mode"`
	TSO       string `json:"tso,omitempty"`
	Timestamp string `json:"timestamp,omitempty"`
}

type InternalTiCDCCluster struct {
	Id                string `json:"id"`
	Name              string `json:"name"`
	ClusterType       string `json:"cluster_type"`
	TidbClusterId     string `json:"tidb_cluster_id"`
	Version           string `json:"version"`
	Region            string `json:"region"`
	ProviderType      string `json:"provider_type"`
	SpecificationCode string `json:"specification_code"`
	Status            string `json:"status"`
	CreatedAt         int64  `json:"created_at"`
	DeployType        string `json:"deploy_type"`
	ControlPlaneArch  string `json:"control_plane_arch"`
	OperatorVersion   string `json:"operator_version"`
}

type ShutdownTiCDCReq struct {
	CloudConfigChangeID uint64 `json:"cloud_config_change_id" binding:"required"`
}
