package com.seer.teach.pay.admin.financial.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.pay.admin.financial.controller.request.AdminPayFinancialReconciliationPageReq;
import com.seer.teach.pay.admin.financial.controller.request.AdminPayFinancialReconciliationQueryReq;
import com.seer.teach.pay.admin.financial.controller.request.AdminPayFinancialReconciliationReq;
import com.seer.teach.pay.admin.financial.controller.response.AdminPayFinancialReconciliationResp;
import com.seer.teach.pay.admin.financial.service.AdminPayFinancialReconciliationService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 财务对账控制器
 *
 * @author ZS
 * @since 2025-09-29
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/financial-reconciliation")
@Tag(name = "管理端 - 财务对账管理")
public class AdminPayFinancialReconciliationController {

    private final AdminPayFinancialReconciliationService adminPayFinancialReconciliationService;

    @GetMapping("/paged")
    @Operation(summary = "分页查询财务对账记录")
    @SaCheckPermission("admin:pay:financial:reconciliation:page")
    public ResultBean<PageListBean<AdminPayFinancialReconciliationResp>> pageList(@Parameter(description = "分页查询参数") @Valid @RequestBody AdminPayFinancialReconciliationPageReq pageRequest) {
        return ResultBean.success(adminPayFinancialReconciliationService.pageList(pageRequest));
    }

    @GetMapping("/list")
    @Operation(summary = "获取财务对账列表")
    @SaCheckPermission("admin:pay:financial:reconciliation:list")
    public ResultBean<List<AdminPayFinancialReconciliationResp>> list(@Parameter(description = "查询参数") @Valid AdminPayFinancialReconciliationQueryReq queryRequest) {
        return ResultBean.success(adminPayFinancialReconciliationService.list(queryRequest));
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取财务对账详情")
    @SaCheckPermission("admin:pay:financial:reconciliation:detail")
    public ResultBean<AdminPayFinancialReconciliationResp> getById(@Parameter(description = "ID") @PathVariable Long id) {
        return ResultBean.success(adminPayFinancialReconciliationService.getDetail(id));
    }

    @PostMapping
    @Operation(summary = "新增财务对账记录")
    @SaCheckPermission("admin:pay:financial:reconciliation:create")
    public ResultBean<Boolean> save(@Parameter(description = "新增参数") @Valid @RequestBody AdminPayFinancialReconciliationReq requestParam) {
        return ResultBean.success(adminPayFinancialReconciliationService.save(requestParam));
    }

    @PutMapping
    @Operation(summary = "更新财务对账记录")
    @SaCheckPermission("admin:pay:financial:reconciliation:update")
    public ResultBean<Boolean> update(@Parameter(description = "更新参数") @Valid @RequestBody AdminPayFinancialReconciliationReq requestParam) {
        return ResultBean.success(adminPayFinancialReconciliationService.updateById(requestParam));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除财务对账记录")
    @SaCheckPermission("admin:pay:financial:reconciliation:delete")
    public ResultBean<Boolean> delete(@Parameter(description = "ID") @PathVariable Long id) {
        return ResultBean.success(adminPayFinancialReconciliationService.deleteById(id));
    }
}