package com.kxs.user.biz.controller.kxsapp;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kxs.common.core.util.R;
import com.kxs.user.api.dto.kxsapp.userAccount.UserAmountVariationListDTO;
import com.kxs.user.api.dto.kxsapp.userAccount.WithdrawDepositDTO;
import com.kxs.user.api.model.KxsUserAdvance;
import com.kxs.user.api.model.KxsUserAmountLog;
import com.kxs.user.api.vo.kxsapp.userAccount.UserAmountVariationListVO;
import com.kxs.user.api.vo.kxsapp.userAccount.WithdrawListVO;
import com.kxs.common.core.constant.enums.UserAdvanceStatusEnum;
import com.kxs.user.biz.service.*;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * 用户相关(UserAccount)控制层
 *
 * @author 系统
 * @since 2024-01-03 09:39:59
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("userAccount")
public class UserAccountController {

    /**
     * 服务对象
     */
    private final KxsUserWithdrawalService kxsUserWithdrawalService;
    private final KxsUserAdvanceService kxsUserAdvanceService;
    private final KxsUserAmountService kxsUserAmountService;
    private final KxsUserBankService kxsUserBankService;
    private final KxsUserAmountLogService kxsUserAmountLogService;



    /**
     * 我的钱包-发起提现
     *
     * @param param 实体对象
     * @return 我的钱包-发起提现
     */
    @PostMapping("/withdrawDeposit")
    public R withdrawDeposit(@RequestBody WithdrawDepositDTO param) {

        return kxsUserWithdrawalService.withdrawDeposit(param);
    }

    /**
     * 我的钱包-提现检查信息
     *
     * @return 我的钱包-提现检查信息
     */
    @GetMapping("/cashAuthFailInfo")
    public R cashAuthFailInfo() {
        return R.ok();
    }

    /**
     * 我的钱包-提现明细预扣款列表
     *
     * @return 我的钱包-提现明细预扣款列表
     */
    @GetMapping("/chargeList")
    public R chargeList(@ParameterObject Page<KxsUserAdvance> page) {

        return R.ok(kxsUserAdvanceService
                .page(page, Wrappers.<KxsUserAdvance>lambdaQuery()
                .eq(KxsUserAdvance::getStatus, UserAdvanceStatusEnum.ADVANCE_NOT_CHARGED.getType())));
    }


    /**
     * 我的钱包-提现记录
     *
     * @param page 分页对象
     * @return 我的钱包-提现记录
     */
    @GetMapping("/withdrawList")
    public R withdrawList(@ParameterObject Page<WithdrawListVO> page) {
        return R.ok(kxsUserWithdrawalService.withdrawListPage(page));
    }


    /**
     * 我的钱包-提现详情
     *
     * @param id 主键ID
     * @return 我的钱包-提现详情
     */
    @GetMapping("/withdrawDetail")
    public R withdrawDetail(@RequestParam("id") Integer id) {
        return R.ok(kxsUserWithdrawalService.withdrawDetail(id));
    }


    /**
     * 我的钱包-账户合计
     *
     * @return 我的钱包-账户合计
     */
    @GetMapping("/myAccount")
    public R myAccount() {
        return R.ok(kxsUserAmountService.myAccount());
    }


    /**
     * 我的钱包-银行卡
     *
     * @return 我的钱包-银行卡
     */
    @GetMapping("/bindBankInfo")
    public R bindBankInfo() {
        return R.ok(kxsUserBankService.bindBankInfo());
    }


    /**
     * 收支明细-列表
     *
     * @param page 分页对象
     * @param param 查询实体
     * @return 收支明细-列表
     */
    @GetMapping("/userAmountVariationList")
    public R userAmountVariationList(@ParameterObject Page<UserAmountVariationListVO> page, @Valid @ParameterObject UserAmountVariationListDTO param) {
        return R.ok(kxsUserAmountLogService.getByPage(page, param));
    }


    /**
     * 收支明细-收益支出合计
     *
     * @param tradeMonth 月份
     * @return 收支明细-收益支出合计
     */
    @GetMapping("/amountInExpendTotal")
    public R amountInExpendTotal(@RequestParam("tradeMonth") String tradeMonth) {
        return R.ok(kxsUserAmountLogService.amountInExpendTotal(tradeMonth));
    }


    /**
     * 收支明细-筛选变动类型
     *
     * @return 收支明细-筛选变动类型
     */
    @GetMapping("/variationTypeList")
    public R variationTypeList(@RequestParam("kind") String kind) {

        return R.ok(kxsUserAmountLogService.variationTypeList(kind));
    }

    /**
     * 余额变动
     *
     * 内部调用
     *
     * @return 收支明细-筛选变动类型
     */
    @PostMapping("/userAmountChange")
    public R userAmountChange(@RequestBody KxsUserAmountLog userAmountLog) {

        return R.ok(kxsUserAmountService.userAmountChange(userAmountLog));
    }





}

