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 com.propertyManagement.pay.support.pay.PayReqModel;
import com.siashan.unipay4j.core.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
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(@NotNull(message = "类型不能为空") Integer type) {
        WxPayRecordBo recordBo = new WxPayRecordBo();
        recordBo.setProprietorId(AuthUtil.getWxUser().getProprietorId());
        recordBo.setOrderType(type);
//        recordBo.setPayState(PayState.NO.getCode());
        return R.ok(iWxPayRecordService.queryList(recordBo));
    }

    /**
     * 支付订单
     */
    @RepeatSubmit()
    @PostMapping("/pay")
    public R<Result<Object>> add(@Validated(AddGroup.class) @RequestBody PayReqModel payReqModel) {
        return R.ok(iWxPayRecordService.pay(payReqModel));
    }

}
