package cvt

import (
	ccproto "github.com/tidbcloud/config-center/proto/config_center"
	ccent "github.com/tidbcloud/devops/entity/cloudconfig"
	serverlessrpc "github.com/tidbcloud/serverless-service/idl/pbgen/proto/rpc"
	"google.golang.org/protobuf/types/known/structpb"
)

type toServerless struct{}

func (c toServerless) NamedParameter(item ccent.NamedParameter) (*serverlessrpc.ParamItem, error) {
	value, err := structpb.NewValue(item.Value)
	if err != nil {
		return nil, err
	}
	return &serverlessrpc.ParamItem{Value: value, Comment: item.Comment}, nil
}

func (c toServerless) ConfigType(configType string) serverlessrpc.ConfigFileType {
	switch configType {
	case ccproto.CHANGEFEED_CONFIG_CHANGEFEED_KAFKA,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_MYSQL,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_S3,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_GCS,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_SERVERLESS,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_PULSAR,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_AZBLOB:
		return serverlessrpc.ConfigFileType_CHANGEFEED_FILE
	case ccproto.CHANGEFEED_CONFIG_CHANGEFEED_URI_KAFKA,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_URI_MYSQL,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_URI_S3,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_URI_GCS,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_URI_SERVERLESS,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_URI_PULSAR,
		ccproto.CHANGEFEED_CONFIG_CHANGEFEED_URI_AZBLOB:
		return serverlessrpc.ConfigFileType_SINK_URI
	default:
		return serverlessrpc.ConfigFileType_CONFIG_FILE_TYPE_UNSPECIFIED
	}
}
