package tidbgroup

import (
	"context"

	"google.golang.org/protobuf/types/known/emptypb"

	globalngv1 "github.com/tidbcloud/tidb-management-service/api/spec/global/nextgen/v1"
	"github.com/tidbcloud/tidb-management-service/nextgen-global-service/domain/service/tidbgroup"
)

type server struct {
	tidbGroupSvc tidbgroup.Service
}

func NewServer(
	tidbGroupSvc tidbgroup.Service,
) globalngv1.TiDBGroupServiceServer {
	return &server{
		tidbGroupSvc: tidbGroupSvc,
	}
}

func (s *server) CreateTiDBGroup(ctx context.Context, req *globalngv1.CreateTiDBGroupRequest) (*globalngv1.TiDBGroup, error) {
	resp, err := s.tidbGroupSvc.CreateTiDBGroup(ctx, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}

func (s *server) DeleteTiDBGroup(ctx context.Context, req *globalngv1.DeleteTiDBGroupRequest) (*emptypb.Empty, error) {
	resp, err := s.tidbGroupSvc.DeleteTiDBGroup(ctx, req)
	if err != nil {
		return nil, err
	}
	return resp, nil
}
