package com.crm.pay.service.impl.pay;

import com.crm.pay.entity.property.DigitalPayPropertyEntity;
import com.crm.pay.service.DigitalPayService;
import com.crm.pay.service.FinanceDepositService;
import com.crm.pay.service.impl.base.BasePayServiceImpl;
import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositAddEntity;
import com.crm.rely.backend.model.pojo.table.FinanceDepositTable;
import com.crm.rely.backend.model.pojo.table.SysRemittanceChannelTable;
import com.crm.rely.backend.util.AESUtil;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @description:
 * @author: houn
 * @create: 2020-05-07 23:45
 */
@Log4j
@Service
public class DigitalPayServiceImpl extends BasePayServiceImpl implements DigitalPayService {

    @Autowired
    private FinanceDepositService balanceService;

    public static void main(String[] args) {
        System.out.println(AESUtil.decrypt("gSHSU/jtuvOFhsg8dkDUg/+CzWne5uRe6Jh7dZOSmGny820VxCg0RzJr3CixzJHQ0gBaOlAjo" +
                "+U0FZlOvZNsPb9Zogv5SBC+cQ1Bfsj+lZc=", "bfa5559109f94c78af615bcf00d52060"));

        System.out.println(AESUtil.encrypt("{\"name\":\"USDT\",\"type\":\"TRC20\",\"url\":\"\",\"address\":\"\"," +
                "\"currency\":\"USD\"}", "bfa5559109f94c78af615bcf00d52060"));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void pay(FinanceDepositAddEntity balanceSaveEntity) throws Exception {

        SysRemittanceChannelTable channel = getPayChannel(balanceSaveEntity.getPayType());

        DigitalPayPropertyEntity payProperty = getPayProperty(channel, DigitalPayPropertyEntity.class);

        balanceSaveEntity.setCurrency(channel.getCurrency());
        balanceSaveEntity.setTransformCurrency(payProperty.getCurrency());
        balanceSaveEntity.setRate(channel.getRate());
        FinanceDepositTable balanceTable = balanceService.save(balanceSaveEntity, channel);
    }
}
