package com.propertyManagement.web.controller.business.api;

import com.propertyManagement.business.domain.bo.WxPayRecordBo;
import com.propertyManagement.business.domain.vo.WxPayRecordVo;
import com.propertyManagement.business.service.IWxPayRecordService;
import com.propertyManagement.business.support.util.AuthUtil;
import com.propertyManagement.common.annotation.RepeatSubmit;
import com.propertyManagement.common.core.controller.BaseController;
import com.propertyManagement.common.core.domain.R;
import com.propertyManagement.common.core.validate.AddGroup;
import com.propertyManagement.common.enums.PayState;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 缴费记录
 *
 * @author liushuai
 * @date 2025-05-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/payRecord")
public class ApiWxPayRecordController extends BaseController {

    private final IWxPayRecordService iWxPayRecordService;

    /**
     * 查询缴费记录列表
     */
    @GetMapping("/listAll")
    public R<List<WxPayRecordVo>> listAll() {
        WxPayRecordBo recordBo = new WxPayRecordBo();
        recordBo.setProprietorId(AuthUtil.getWxUser().getProprietorId());
        recordBo.setPayState(PayState.NO.getCode());
        return R.ok(iWxPayRecordService.queryList(recordBo));
    }

    /**
     * 新增缴费记录
     */
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WxPayRecordBo bo) {
        return toAjax(iWxPayRecordService.insertByBo(bo));
    }

}
