package reservedcapacitytemplate

import (
	"context"

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

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

type server struct {
	globalngv1.UnimplementedReservedCapacityTemplateServiceServer

	svc reservedcapacitytemplatesvc.Service
}

func NewServer(svc reservedcapacitytemplatesvc.Service) globalngv1.ReservedCapacityTemplateServiceServer {
	return &server{svc: svc}
}

func (s *server) CreateReservedCapacityTemplate(
	ctx context.Context,
	req *globalngv1.CreateReservedCapacityTemplateRequest,
) (*globalngv1.ReservedCapacityTemplate, error) {
	return s.svc.Create(ctx, req)
}

func (s *server) GetReservedCapacityTemplate(
	ctx context.Context,
	req *globalngv1.GetReservedCapacityTemplateRequest,
) (*globalngv1.ReservedCapacityTemplate, error) {
	return s.svc.Get(ctx, req)
}

func (s *server) ListReservedCapacityTemplates(
	ctx context.Context,
	req *globalngv1.ListReservedCapacityTemplatesRequest,
) (*globalngv1.ListReservedCapacityTemplatesResponse, error) {
	return s.svc.List(ctx, req)
}

func (s *server) UpdateReservedCapacityTemplateStatus(
	ctx context.Context,
	req *globalngv1.UpdateReservedCapacityTemplateStatusRequest,
) (*globalngv1.ReservedCapacityTemplate, error) {
	return s.svc.UpdateStatus(ctx, req)
}

func (s *server) DeleteReservedCapacityTemplate(ctx context.Context, req *globalngv1.DeleteReservedCapacityTemplateRequest) (*emptypb.Empty, error) {
	if err := s.svc.Delete(ctx, req); err != nil {
		return nil, err
	}
	return &emptypb.Empty{}, nil
}
