package com.aircraft.modules.order.controller;


import com.aircraft.modules.order.biz.OrderBiz;
import com.aircraft.modules.order.domain.SettlementDetail;
import com.aircraft.modules.order.domain.SettlementMain;
import com.aircraft.modules.order.domain.vo.GenerateSettlementOrderConfirmVO;
import com.aircraft.modules.order.domain.vo.PrintSettlementOrderDataVO;
import com.aircraft.modules.order.service.ISettlementMainService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 订单结算主表 前端控制器
 * </p>
 *
 * @author cli
 * @since 2025-07-10
 */
@RestController
@RequestMapping("/api/settlementOrder")
@Api(tags = "结算单管理")
public class SettlementMainController {

    @Resource
    private OrderBiz orderBiz;
    @Resource
    ISettlementMainService settlementMainService;

    @ApiOperation("查询结算订单列表")
    @GetMapping("/allSettlementOrder")
    public ResponseEntity<IPage<SettlementMain>> allSettlementOrderList(
            @ApiParam(value = "结算批次号", required = false, example = "JS_2025072500001")
            @RequestParam (value = "结算批次号", required = false) String batchNo, Page page) {
        return ResponseEntity.ok(settlementMainService.allSettlementOrderList(batchNo, page));
    }

    @ApiOperation("生成结算订单")
    @PostMapping("/generateSettlementOrder")
    public ResponseEntity<String> generateSettlementOrder(
            @ApiParam(value = "订单ID集合", required = true)
            @RequestBody List<Long> orderIds) {
        orderBiz.generateSettlementOrder(orderIds);
        return new ResponseEntity<>("生成结算订单成功",HttpStatus.OK);
    }

    @ApiOperation("结算订单详情")
    @GetMapping("/querySettlementOrderDetail/{settlementOrderId}")
    public ResponseEntity<List<SettlementDetail>> querySettlementOrderDetail(
            @ApiParam(value = "结算订单ID", required = true, example = "1948997367110451201")
            @PathVariable("settlementOrderId") Long settlementOrderId) {
        return new ResponseEntity<>(orderBiz.querySettlementOrderDetail(settlementOrderId),HttpStatus.OK);
    }

    @ApiOperation("打印结算单数据-返回对应的数据集，前端进行打印PDF")
    @GetMapping("/printSettlementOrder/{settlementOrderId}")
    public ResponseEntity<PrintSettlementOrderDataVO> printSettlementOrder(
            @ApiParam(value = "结算订单ID", required = true, example = "1948997367110451201")
            @PathVariable("settlementOrderId") Long settlementOrderId) {
        return new ResponseEntity<>(orderBiz.printSettlementOrder(settlementOrderId),HttpStatus.OK);
    }

    @ApiOperation("更新结算单状态")
    @PutMapping("/updateSettlementOrderStatus/{settlementOrderId}/{settlementOrderStatus}")
    public ResponseEntity<Object> updateSettlementOrderStatus(
            @ApiParam(value = "结算订单ID", required = true, example = "1946509536383438850")
            @PathVariable("settlementOrderId") Long settlementOrderId,
            @ApiParam(value = "结算单状态: 0=结算中, 1=已确认, 2=已完成, 3=结算完成, 4=已取消", required = true, example = "1")
            @PathVariable("settlementOrderStatus") Integer settlementOrderStatus) {
        orderBiz.updateSettlementOrderStatus(settlementOrderId, settlementOrderStatus);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation(value = "获取生成结算单确认列表")
    @PostMapping("/generateSettlementOrderConfirmList")
    public ResponseEntity<List<GenerateSettlementOrderConfirmVO>> generateSettlementOrderConfirmList(
            @ApiParam(value = "订单ID集合(1946509536383438850)", required = true)
            @RequestBody List<Long> orderIds){

        return new ResponseEntity<>(orderBiz.generateSettlementOrderConfirmList(orderIds), HttpStatus.OK);
    }
}

