package com.cf.imes.module.executor.controller.admin.manage.pack;

import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.executor.controller.admin.manage.pack.heapsplit.HeapSplitSaveReqVO;
import com.cf.imes.module.executor.controller.admin.manage.pack.heapsplit.OrdersHeapSplitDetailRespVO;
import com.cf.imes.module.executor.service.heapsplit.HeapSplitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.cf.imes.framework.common.pojo.CommonResult.success;

/**
 *
 *
 * @author Gqr
 * @since 2026/3/13 14:05
 */
@Tag(name = "管理后台 - 分堆管理 ")
@RestController
@RequestMapping("/manage/heapsplit")
@Validated
public class HeapSplitController {

    @Resource
    private HeapSplitService heapSplitService;

    @PostMapping("")
    @Operation(summary = "保存分堆")
    @PreAuthorize("@ss.hasPermission('manage:heapsplit:query')")
    public CommonResult<Boolean> saveHeapsplit(@Valid @RequestBody HeapSplitSaveReqVO reqVO) {
        heapSplitService.saveHeapsplit(reqVO);
        return success(true);
    }

    @PostMapping("/details")
    @Operation(summary = "查询分堆详情")
    @Parameter(name = "orderIds", description = "订单ID列表", required = true)
    @PreAuthorize("@ss.hasPermission('manage:heapsplit:save')")
    public CommonResult<OrdersHeapSplitDetailRespVO> getOrdersHeapSplitDetail(@RequestBody @NotEmpty(message = "订单ID不能为空") List<Long> orderIds) {
        return success(heapSplitService.getOrdersHeapSplitedDetail(orderIds));
    }
}