package repo

import (
	"context"

	"github.com/tidbcloud/pkgv2/bizerr"
	"github.com/tidbcloud/serverless-service/internal/domain/constant"
	"github.com/tidbcloud/serverless-service/internal/domain/entity"
)

// PrivateLinkConnectionRepo defines persistence operations for PrivateLinkConnection entity.
type PrivateLinkConnectionRepo interface {
	// Create inserts a new PrivateLinkConnection record.
	Create(ctx context.Context, plc *entity.PrivateLinkConnection) (*entity.PrivateLinkConnection, bizerr.BizError)

	// GetById returns a PrivateLinkConnection by cluster id and private link connection id.
	GetById(ctx context.Context, clusterId, id string) (*entity.PrivateLinkConnection, bizerr.BizError)

	// GetByID returns a PrivateLinkConnection by private link connection id.
	GetByID(ctx context.Context, id string) (*entity.PrivateLinkConnection, bizerr.BizError)

	// ListByFilter lists PrivateLinkConnections by filter with pagination.
	ListByFilter(
		ctx context.Context,
		filter *entity.ListPrivateLinkConnectionFilter,
	) ([]*entity.PrivateLinkConnection, bizerr.BizError)

	// CountByFilter returns total count for given filter.
	CountByFilter(ctx context.Context, filter *entity.ListPrivateLinkConnectionFilter) (int64, bizerr.BizError)

	// Save updates (upsert) a PrivateLinkConnection record.
	Save(ctx context.Context, plc *entity.PrivateLinkConnection) (*entity.PrivateLinkConnection, bizerr.BizError)

	// DeleteById soft delete a PrivateLinkConnection cluster id and private link connection id.
	DeleteById(ctx context.Context, clusterId, id string) bizerr.BizError
}

type PrivateLinkConnectionLinkRepo interface {
	// Create inserts a new PrivateLinkConnectionLink record.
	Create(
		ctx context.Context,
		link *entity.PrivateLinkConnectionLink,
	) (*entity.PrivateLinkConnectionLink, bizerr.BizError)

	// ListByPrivateLinkConnectionID lists PrivateLinkConnectionLink by private link connection id.
	ListByPrivateLinkConnectionID(
		ctx context.Context,
		clusterId, privateLinkConnectionID string,
	) ([]*entity.PrivateLinkConnectionLink, bizerr.BizError)

	Delete(ctx context.Context, clusterId, privateLinkConnectionID, bizID string) bizerr.BizError

	// DeleteByPrivateLinkConnectionID deletes all links under a private link connection.
	DeleteByPrivateLinkConnectionID(ctx context.Context, clusterId, privateLinkConnectionID string) bizerr.BizError
}
type PLCAttachDomainRepo interface {
	// Create inserts a new attach-domain record.
	Create(ctx context.Context, d *entity.PLCAttachDomain) (*entity.PLCAttachDomain, bizerr.BizError)
	// Save updates (upsert) an attach-domain record.
	Save(ctx context.Context, d *entity.PLCAttachDomain) (*entity.PLCAttachDomain, bizerr.BizError)
	// Get get a attach domain
	Get(ctx context.Context, clusterID, plcID, attachDomainID string) (*entity.PLCAttachDomain, bizerr.BizError)
	// ListByPLC lists by private link connection.
	ListByFilter(
		ctx context.Context,
		filter entity.ListPLCAttachDomainsFilter,
	) ([]*entity.PLCAttachDomain, bizerr.BizError)
	// CountByPLC returns total count for given private link connection.
	CountByPLC(ctx context.Context, clusterID, plcID string) (int64, bizerr.BizError)
	// CheckHostedZone check if hosted zone and unique id exist.
	CheckHostedZone(ctx context.Context, hostedZone, unique_id string) (bool, bizerr.BizError)
	// DeleteByID deletes by primary id.
	DeleteByID(ctx context.Context, clusterID, plcID, attachDomainID string) bizerr.BizError
}

type PLCDomainRecordRepo interface {
	// BatchInsert inserts multiple domain records in a batch.
	BatchInsert(ctx context.Context, records []*entity.PLCDomainRecord) bizerr.BizError
	ListByFilter(
		ctx context.Context,
		filter *entity.ListPLCDomainRecordsFilter,
	) ([]*entity.PLCDomainRecord, bizerr.BizError)
	// ActiveByAttachDomainID batch updates records state to active.
	ActiveByAttachDomainID(
		ctx context.Context,
		clusterID, plcID, attachDomainID string,
		awsRoute53CreateChangeID string,
		aliDNSRecordID int64,
	) bizerr.BizError
	// SoftDeleteByAttachDomain deletes all records under the private link
	SoftDeleteByPLC(ctx context.Context, clusterID, plcID string) bizerr.BizError
	// SoftDeleteByID deletes all records under the attach domain.
	SoftDeleteByID(ctx context.Context, clusterID, plcID string, attachDomainID string) bizerr.BizError
	// UpdateStateByAttachDomainID updates records state and message by attach domain id.
	UpdateStateByAttachDomainID(
		ctx context.Context,
		clusterID, plcID, attachDomainID string,
		state constant.PLCDomainRecordState,
		message string,
	) bizerr.BizError
	// UpdateByID updates records
	UpdateByID(
		ctx context.Context,
		clusterID, plcID, attachDomainID string,
		awsRoute53DeleteChangeID string,
	) bizerr.BizError
}
