package cn.com.ctop.toutiao.modules.material.controller;

import cn.com.ctop.toutiao.modules.material.service.IByteDanceTransferBalanceService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 转账余额
 */
@Slf4j
@RestController
@RequestMapping("/bytedance/transfer")
public class BytedancAccountTransferBalanceController {
    @Resource
    private IByteDanceTransferBalanceService balanceService;

    /**
     * 查询账户转账余额
     */
    @RequestMapping(value = "/getTransferBalance")
    public Result getTransferBalance(@RequestBody List<Long> accountIdList) {
        try {
            return balanceService.getTransferBalance(accountIdList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    /**
     * 获取最大可转余额
     *
     * @param data 入参格式
     *             {"account_id":8485602,"transfer_direction":"TRANSFER_IN","target_account_id_list":[1111111111111111]}
     */
    @RequestMapping(value = "/getCanTransferBalance")
    public Result getCanTransferBalance(@RequestBody JSONObject data) {
        try {
            return balanceService.getCanTransferBalance(data);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    /**
     * 发起转账
     *
     * @param data 入参格式
     *             {"account_id":8485602,"transfer_direction":"TRANSFER_IN","target_account_detail_list":[{"account_id":8485602,"transfer_capital_detail_list":[{"capital_type":"CREDIT_GENERAL","transfer_amount":50000}]}]}
     */
    @RequestMapping(value = "/createTransfer")
    public Result createTransfer(@RequestBody JSONObject data) {
        try {
            return balanceService.createTransfer(data);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    /**
     * 查询转账单信息（代理）
     *
     * @param transferNo 转账单号
     */
    @RequestMapping(value = "/queryTransferDetail")
    public Result queryTransferDetail(String transferNo) {
        try {
            return balanceService.queryTransferDetail(transferNo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }


}
