<?php

namespace App\Services\ColdStorage;

use App\Models\ColdStorage\ColdStorage;
use App\Services\Wallet\WalletService;

class ColdStorageService {

    public function transferCheck($network, $amount, $currency) {

        $coldStorage = ColdStorage::whereNull('cold_storage_transaction_id')->where('network_id', $network)->where('cold_min_balance_amount', '<=', $amount)->where('currency_id', $currency)->first();

        if(!$coldStorage) return;

        $transaction = (new WalletService())->withdrawSystem($currency, $network, $coldStorage->address, $coldStorage->cold_transfer_amount);

        $coldStorage->cold_storage_transaction_id = $transaction->id;
        $coldStorage->update();
    }
}
