package admin

import (
	"github.com/gofiber/fiber/v2"

	"github.com/break/junhong_cmp_fiber/internal/model/dto"
	batchAllocationService "github.com/break/junhong_cmp_fiber/internal/service/shop_package_batch_allocation"
	"github.com/break/junhong_cmp_fiber/pkg/errors"
	"github.com/break/junhong_cmp_fiber/pkg/response"
)

type ShopPackageBatchAllocationHandler struct {
	service *batchAllocationService.Service
}

func NewShopPackageBatchAllocationHandler(service *batchAllocationService.Service) *ShopPackageBatchAllocationHandler {
	return &ShopPackageBatchAllocationHandler{service: service}
}

// BatchAllocate 批量分配套餐
func (h *ShopPackageBatchAllocationHandler) BatchAllocate(c *fiber.Ctx) error {
	var req dto.BatchAllocatePackagesRequest
	if err := c.BodyParser(&req); err != nil {
		return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
	}

	if err := h.service.BatchAllocate(c.UserContext(), &req); err != nil {
		return err
	}

	return response.Success(c, nil)
}
