package com.jeesharp.business.modules.finance.payorder.controller;

import com.jeesharp.business.modules.finance.payorder.application.PayOrderApplicationService;
import com.jeesharp.business.modules.finance.payorder.dto.PayOrderSaveDTO;
import com.jeesharp.business.modules.finance.payorder.entity.PayOrder;
import com.jeesharp.business.modules.finance.payorder.vo.PayOrderInfoVO;
import com.jeesharp.business.modules.finance.payorder.vo.PayOrderListVO;
import com.jeesharp.business.modules.finance.payorder.vo.PayOrderQueryVO;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import com.jeesharp.framework.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 支付单管理端 REST：分页、详情、保存与删除。
 *
 * @author jeesharp
 * @since 2026-05-08
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/finance/payOrder/v1")
@Tag(name = "支付单")
@AllArgsConstructor
public class PayOrderController extends BaseController {

    private final PayOrderApplicationService payOrderApplicationService;

    @GetMapping("info")
    @Operation(summary = "获取详情")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:payOrder:info')")
    public AjaxResult<PayOrderInfoVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(payOrderApplicationService.get(id));
    }

    @PostMapping("list")
    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:payOrder:list')")
    public AjaxResult<PageRespVO<PayOrderListVO>> list(@RequestBody PayOrderQueryVO query) {
        return AjaxResult.okData(payOrderApplicationService.findPage(new Page<>(query), query));
    }

    @PostMapping("save")
    @Operation(summary = "保存")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:payOrder:save')")
    public AjaxResult<Void> save(@RequestBody @Valid PayOrderSaveDTO dto) {
        payOrderApplicationService.save(dto);
        return AjaxResult.ok("保存成功");
    }

    @GetMapping("delete")
    @Operation(summary = "删除")
    @PreAuthorize("@ss.hasPermission('manager:business:finance:payOrder:delete')")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        payOrderApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }
}
