package com.sonic.lion.controller.web;

import com.sonic.common.auth.domains.Session;
import com.sonic.common.rpc.Result;
import com.sonic.lion.domain.input.BindBankCardInput;
import com.sonic.lion.domain.output.WalletOutput;
import com.sonic.lion.domain.req.BillListReq;
import com.sonic.lion.domain.resp.SummaryBillListResp;
import com.sonic.lion.service.AccountBuffBillService;
import com.sonic.lion.service.AccountBuffService;
import com.sonic.lion.service.PayAccountFundThirdService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付账号
 */
@RestController
public class AccountController {

    @Autowired
    private AccountBuffService accountBuffService;
    @Autowired
    private AccountBuffBillService accountBuffBillService;
    @Autowired
    private PayAccountFundThirdService payAccountFundThirdService;

    @ApiOperation(value = "钱包余额", tags = "支付账号")
    @PostMapping("/web/pay/account/wallet")
    public Result<WalletOutput> wallet(@ApiParam(hidden = true) Session session) {
        return Result.success(accountBuffService.wallet(session.getUserId()));
    }

    @ApiOperation(value = "钱包流水", tags = "支付账号")
    @PostMapping("/web/pay/account/bill-list")
    public Result<SummaryBillListResp> billListSummary(@RequestBody @Validated BillListReq req, @ApiParam(hidden = true) Session session) {
        return Result.success(accountBuffBillService.billListSummary(req, session));
    }

    @ApiOperation(value = "绑定银行卡", tags = "支付账号")
    @PostMapping("/web/pay/account/bind-bank-card")
    public Result<Void> bindBankCard(@RequestBody @Validated BindBankCardInput input, @ApiParam(hidden = true) Session session) {
        input.setUid(session.getUserId());
        payAccountFundThirdService.bindBankCard(input);
        return Result.success();
    }

}
