package com.crm.ucard.controller;

import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.entity.ucard.vaultody.VaultodyGenerateDepositAddressEntity;
import com.crm.ucard.service.VaultodyService;
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("/vaultody/api")
public class VaultodyApiController {

    @Autowired
    private VaultodyService vaultodyService;

    /**
     * 生成钱包地址
     * @param entity:
     * @return void
     */
    @PostMapping("/generate/deposit/address")
    public BaseResultDto generateDepositAddress(@RequestBody VaultodyGenerateDepositAddressEntity entity) throws Exception {
        String address = vaultodyService.generateDepositAddress(entity);
        try {
            vaultodyService.linkAddress(entity.getBlockchain(), address);
        } catch (Exception e){
            log.error("链接钱包地址失败", e);
        }

        return BaseResultDto.success(Constants.SUCCESS,address);
    }

}
