package com.ytpm.middle.controller;

import com.ytpm.general.Result;
import com.ytpm.general.ResultTable;
import com.ytpm.middle.param.ConfirmReceiveParam;
import com.ytpm.middle.param.PaymentItemParam;
import com.ytpm.middle.param.PaymentListParam;
import com.ytpm.middle.service.FinanceService;
import com.ytpm.middle.view.FinancePaymentVO;
import com.ytpm.middle.view.MiddleUserInfo;
import com.ytpm.middle.view.PaymentItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * @author Marx
 * @date 2025/8/6 11:58
 */
@Api(tags = "财务管理")
@RestController
@RequestMapping("/finance")
public class FinanceController {

    @Resource
    private FinanceService financeService;

    @ApiOperation("查询缴费项目列表")
    @PostMapping("/queryItemList")
    public ResultTable<PaymentItemVO> queryItemList(@RequestBody PaymentItemParam param) {
        return financeService.queryList(param);
    }

    @ApiOperation("新增缴费项目")
    @PostMapping("/addItem")
    public Result<String> addItem(@RequestBody PaymentItemParam param, @ApiIgnore @AuthenticationPrincipal MiddleUserInfo userInfo) {
        param.setDefaultParam(userInfo.getUserId());
        return financeService.addItem(param);
    }

    @ApiOperation("修改缴费项目")
    @PostMapping("/updateItem")
    public Result<String> updateItem(@RequestBody PaymentItemParam param, @ApiIgnore @AuthenticationPrincipal MiddleUserInfo userInfo) {
        param.setUpdateParam(userInfo.getUserId());
        return financeService.updateItem(param);
    }

    @ApiOperation("删除缴费项目")
    @GetMapping("/deleteItem")
    public Result<String> deleteItem(@RequestParam(name = "itemId")String itemId, @ApiIgnore @AuthenticationPrincipal MiddleUserInfo userInfo) {
        return financeService.delItem(itemId,userInfo.getUserId());
    }

    @ApiOperation("缴费单列表")
    @PostMapping("/paymentList")
    public ResultTable<FinancePaymentVO> paymentList(@RequestBody PaymentListParam param) {
        return financeService.paymentList(param);
    }

    @ApiOperation("查看缴费单明细")
    @GetMapping("/paymentDetail")
    public Result<FinancePaymentVO> paymentDetail(@RequestParam(name = "paymentId")String paymentId) {
        return financeService.paymentDetail(paymentId);
    }

    @ApiOperation("确认收款")
    @PostMapping("/confirmReceive")
    public Result<String> confirmReceive(@RequestBody ConfirmReceiveParam param,@ApiIgnore @AuthenticationPrincipal MiddleUserInfo userInfo) {
        param.setUpdateParam(userInfo.getUserId());
        return financeService.confirmReceive(param);
    }

}
