package region

import (
	"context"

	"go.opentelemetry.io/otel"

	openapingv1beta2 "github.com/tidbcloud/tidb-management-service/api/spec/tidb_cloud_open_api/nextgen/v1beta2"
	tidbmgmtservicev1 "github.com/tidbcloud/tidb-management-service/api/spec/tidb_mgmt_service/v1"
	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-service/domain/adapter/account"
	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-service/domain/adapter/nextgenglobal"
	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-service/domain/entity"
)

var tracer = otel.Tracer("App.nextgen.Region")

type serverImpl struct {
	nextgenCli      nextgenglobal.NextGenGlobal
	accountCli      account.Client
	customStatusSvc clusterCustomStatusLister
}

type clusterCustomStatusLister interface {
	ListClusterCustomStatus(
		ctx context.Context,
		clusterIDs []uint64,
		statusTypes []tidbmgmtservicev1.CustomStatusType,
		includeDeleted bool,
	) (map[uint64][]*entity.ClusterCustomStatus, error)
}

func NewServer(
	nextgenCli nextgenglobal.NextGenGlobal,
	accountCli account.Client,
	customStatusSvc clusterCustomStatusLister,
) openapingv1beta2.RegionServiceServer {
	return &serverImpl{
		nextgenCli:      nextgenCli,
		accountCli:      accountCli,
		customStatusSvc: customStatusSvc,
	}
}
