package com.kym.miniapp.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.kym.common.R;
import com.kym.entity.queryParams.CommonQueryParam;
import com.kym.service.AccountService;
import com.kym.service.RefundLogService;
import com.kym.service.WalletDetailService;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户账户表 前端控制器
 * </p>
 *
 * @author skyline
 * @since 2023-08-07
 */
@RestController
@RequestMapping("/account/")
public class AccountController {

    private final AccountService accountService;

    private final WalletDetailService walletDetailService;

    private final RefundLogService refundLogService;

    public AccountController(AccountService accountService, WalletDetailService walletDetailService, RefundLogService refundLogService) {
        this.accountService = accountService;
        this.walletDetailService = walletDetailService;
        this.refundLogService = refundLogService;
    }

    /**
     * 钱包总览
     *
     * @return
     */
    @GetMapping("/balance")
    public R<?> balance() {
        return R.success(accountService.getAccountByUserId(StpUtil.getLoginIdAsLong()));
    }


    /**
     * 钱包明细列表
     *
     * @param type
     * @return
     */
    @GetMapping("/walletDetailList")
    public R<?> walletDetailList(@RequestParam(name = "type", defaultValue = "0", required = false) int type) {
        return R.success(walletDetailService.listWalletDetail(type));
    }


    /**
     * 钱包明细
     *
     * @param type
     * @return
     */
    @GetMapping("/walletDetail")
    public R<?> walletDetailList(@RequestParam(name = "type", defaultValue = "0", required = false) int type,
                                 @RequestParam(name = "orderNo", required = false) String orderNo) {
        return R.success(walletDetailService.getWalletDetailByOrderNo(orderNo, type));
    }

    /**
     * 退款记录
     *
     * @param params
     * @return
     */
    @PostMapping("/listRefund")
    public R<?> listRefund(@RequestBody CommonQueryParam params) {
        return R.success(refundLogService.listRefundLogForApp(params));
    }

}
