package cn.iocoder.yudao.module.member.controller.app.billing;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.controller.admin.billing.vo.BillingPageReqVO;
import cn.iocoder.yudao.module.member.controller.admin.billing.vo.BillingRespMoneyVO;
import cn.iocoder.yudao.module.member.controller.admin.billing.vo.BillingRespVO;
import cn.iocoder.yudao.module.member.controller.admin.billing.vo.BillingSaveReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.billing.BillingDO;
import cn.iocoder.yudao.module.member.service.billing.BillingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "小程序 - 开票记录")
@RestController
@RequestMapping("/t/billing")
@Validated
public class AppBillingController {

    @Resource
    private BillingService billingService;

    @PostMapping("/create")
    @Operation(summary = "创建开票记录")
    public CommonResult<String> createBilling(@Valid @RequestBody BillingSaveReqVO createReqVO) {
        return success(billingService.createBilling(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新开票记录")
    public CommonResult<Boolean> updateBilling(@Valid @RequestBody BillingSaveReqVO updateReqVO) {
        billingService.updateBilling(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除开票记录")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteBilling(@RequestParam("id") String id) {
        billingService.deleteBilling(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得开票记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BillingRespVO> getBilling(@RequestParam("id") String id) {
        BillingDO billing = billingService.getBilling(id);
        return success(BeanUtils.toBean(billing, BillingRespVO.class));
    }
    @GetMapping("/moeny")
    @Operation(summary = "获得开票金额与未开票金额")
    public CommonResult<BillingRespMoneyVO> getBillingPage(@RequestParam("userId")Long userId) {
        return success(billingService.getHaveWithoutMoney(userId));
    }
    @GetMapping("/page")
    @Operation(summary = "获得开票记录分页")
    public CommonResult<PageResult<BillingRespVO>> getBillingPage(@Valid BillingPageReqVO pageReqVO) {
        PageResult<BillingDO> pageResult = billingService.getBillingPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, BillingRespVO.class));
    }
}