package com.crm.ucard.controller;

import com.alibaba.fastjson.JSON;
import com.crm.rely.backend.core.dto.wasabi.WasabiNotifyResultDto;
import com.crm.rely.backend.core.entity.ucard.crypto.currency.callback.CryptoAddressCallbackEntity;
import com.crm.ucard.service.CryptoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/crypto")
public class CryptoNotifyController {

    @Autowired
    private CryptoService cryptoService;

    @PostMapping("/callback")
    public WasabiNotifyResultDto notify(@RequestBody CryptoAddressCallbackEntity entity) throws Exception {
        try {
            log.info("crypto回调通知开始：" + JSON.toJSONString(entity));
            cryptoService.notify(entity);
            log.info("crypto回调通知结束");
            return WasabiNotifyResultDto.success();
        } catch (Exception e) {
            log.error("crypto回调通知处理失败", e);
            return WasabiNotifyResultDto.error();
        }
    }

}
