package encryptionchange

import (
	"context"

	"github.com/tidbcloud/tidb-management-service/nextgen-global-service/domain/entity"
)

type GenMetaRequest struct {
	ClusterId    string
	SharedPoolId string
	KeyspaceName string // cluster ID as string — agreed with kernel team
	Mode         string // "enable-cmek" (the only mode used by control plane)
	Vendor       string // "aws", "aliyun"
	KmsRegion    string // "us-west-2", "cn-hangzhou"
	CmekId       string // KMS key ARN or Aliyun Key ID
	Endpoint     string // KMS endpoint (optional, for custom KMS endpoints e.g. Aliyun)
	// ExternalId is forwarded verbatim as encryption_context.ExternalId.
	// For AWS CMEK it is the customer-facing AssumeRole ExternalId (the
	// caller's org/tenant id as decimal string). Empty = no context flag.
	ExternalId string
}

type GenMetaResponse struct {
	FileId           uint64
	PdUpdated        bool
	PdAfter          PdAfterState
	OwnerStoreId     uint64
	EncryptionConfig EncryptionConfigInfo
}

type PdAfterState struct {
	CurrentFileId uint64
	NextFileId    uint64
}

type EncryptionConfigInfo struct {
	Enabled bool
	CmekId  string
	Vendor  string
	Region  string
}

type SyncMetaRequest struct {
	ClusterId    string
	SharedPoolId string
	KeyspaceName string // cluster ID as string
}

type SyncMetaResponse struct {
	Started       bool
	Running       bool
	CurrentFileId uint64
	NextFileId    uint64
}

type StatusRequest struct {
	ClusterId    string
	SharedPoolId string
	KeyspaceName string // cluster ID as string
}

type StatusResponse struct {
	KeyspaceName      string
	EncryptionEnabled bool
	MetaState         MetaStateInfo
	EncryptionConfig  EncryptionConfigInfo
}

type MetaStateInfo struct {
	CurrentFileId uint64
	NextFileId    uint64 // 0 = converged
}

//go:generate go run go.uber.org/mock/mockgen@latest -source=$GOFILE -package=mock_$GOPACKAGE -destination=./mock_$GOPACKAGE/mock_$GOFILE
type Executor interface {
	GenMeta(ctx context.Context, region *entity.Region, req *GenMetaRequest) (*GenMetaResponse, error)
	SyncMeta(ctx context.Context, region *entity.Region, req *SyncMetaRequest) (*SyncMetaResponse, error)
	GetStatus(ctx context.Context, region *entity.Region, req *StatusRequest) (*StatusResponse, error)
}
