package com.crm.ucard.controller;

import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.ucard.service.VaultodyService;
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/vaultody")
public class VaultodyNotifyController {

    @Autowired
    private VaultodyService vaultodyService;

    @PostMapping("/callback")
    public BaseResultDto notify(@RequestBody String content, @RequestHeader("x-signature") String signature) throws Exception {
        try {

            log.info("Vaultody回调通知开始：{},signature:{}", content, signature);

            if (Strings.isNullOrEmpty(content) || Strings.isNullOrEmpty(signature)) {
                log.error("Vaultody回调通知处理失败,数据为空，content:{},signature:{}", content, signature);
                return BaseResultDto.error();
            }
            vaultodyService.notify(content, signature);
            log.info("crypto回调通知结束");
            return BaseResultDto.success();
        } catch (Exception e) {
            log.error("crypto回调通知处理失败", e);
            return BaseResultDto.error();
        }
    }

}
