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

import com.jeesharp.business.modules.finance.paymentrecord.application.PayRecordApplicationService;
import com.jeesharp.business.modules.finance.paymentrecord.dto.PayRecordSaveDTO;
import com.jeesharp.business.modules.finance.paymentrecord.entity.PayRecord;
import com.jeesharp.business.modules.finance.paymentrecord.vo.PayRecordInfoVO;
import com.jeesharp.business.modules.finance.paymentrecord.vo.PayRecordListVO;
import com.jeesharp.business.modules.finance.paymentrecord.vo.PayRecordQueryVO;
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-09
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/finance/payRecord/v1")
@Tag(name = "支付记录")
@AllArgsConstructor
public class PayRecordController extends BaseController {

    private final PayRecordApplicationService payRecordApplicationService;

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

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

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

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