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

import com.propertyManagement.business.domain.bo.WxLiveBillBo;
import com.propertyManagement.business.domain.vo.LoginWxUser;
import com.propertyManagement.business.domain.vo.WxLiveBillVo;
import com.propertyManagement.business.service.IWxLiveBillService;
import com.propertyManagement.business.support.util.AuthUtil;
import com.propertyManagement.common.core.controller.BaseController;
import com.propertyManagement.common.core.domain.R;
import com.propertyManagement.common.enums.LiveBillState;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 缴费账单
 *
 * @author liushuai
 * @date 2025-05-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/liveBill")
public class ApiWxLiveBillController extends BaseController {

    private final IWxLiveBillService iWxLiveBillService;

    /**
     * 查询待缴账单列表
     */
    @GetMapping("/listAll")
    public R<List<WxLiveBillVo>> listAll(@NotEmpty(message = "类型不能为空") Integer type) {
        LoginWxUser wxUser = AuthUtil.getWxUser();
        WxLiveBillBo wxLiveBillBo = new WxLiveBillBo();
        wxLiveBillBo.setProprietorId(wxUser.getProprietorId());
        wxLiveBillBo.setType(type);
        wxLiveBillBo.setState(LiveBillState.NO.getCode());
        return R.ok(iWxLiveBillService.queryList(wxLiveBillBo));
    }

    /**
     * 创建缴费账单
     */
    @PostMapping("/add")
    public R<WxLiveBillBo> add(WxLiveBillBo bo) {
        return R.ok(iWxLiveBillService.add(bo));
    }

}
