<?php

namespace App\Console\Commands\QuickFixes;

use App\Models\Network\Network;
use App\Repositories\Currency\CurrencyRepository;
use App\Services\PaymentGateways\Coin\Bnb\Api\BnbGateway;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class FixBepContractCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'quick-fix:bep-contracts';

    protected $candles = [];

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        try {

            $currencyRepository = new CurrencyRepository();

            $filter['type'] = 'coin';

            $currencies = $currencyRepository->getReport($filter, false);

            $currencies->each(function ($currency) {

                if(isset($currency->networks) && (in_array(NETWORK_BNB, $currency->networks->pluck('id')) || in_array(NETWORK_BEP, $currency->networks->pluck('id')))) {
                    $currency->bep_contract = $currency->contract;
                }
            });

        } catch (\Exception $e) {
            Log::error($e);
            Log::info('Could not update BNB/BEP balances');
        }
    }
}
