package com.crm.ucard.controller;

import com.alibaba.fastjson.JSON;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.entity.ucard.UcardDepositEntity;
import com.crm.ucard.service.UcardWalletService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/ucard/wallet")
public class UcardWalletController {

    @Autowired
    private UcardWalletService cardWalletService;

    @PostMapping("/deposit")
    public BaseResultDto deposit(@RequestBody UcardDepositEntity entity) throws Exception {
        log.info(String.format("ucard wallet deposit: %s", JSON.toJSONString(entity)));
        try {
            return cardWalletService.ucardWalletDeposit(entity);
        } catch (Exception e) {
            return BaseResultDto.error("system error");
        }


    }

    @PostMapping("/withdraw")
    public BaseResultDto withdraw(@RequestBody UcardDepositEntity entity) throws Exception {
        log.info(String.format("ucard wallet withdraw: %s", JSON.toJSONString(entity)));
        try {
            return cardWalletService.ucardWalletWithdraw(entity);
        } catch (Exception e) {
            return BaseResultDto.error("system error");
        }
    }

}
