<?php

namespace App\Console\Commands\QuickFixes;

use App\Models\Currency\Currency;
use App\Models\User\User;
use App\Models\Wallet\Wallet;
use Illuminate\Console\Command;

class FundWalletVitexCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'one-time-task:deposit-vitex-campaign';

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

    public $i = 0;

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $currency = Currency::where('symbol', 'VITEX')->first();

        User::where('created_at', '<', '2025-02-28 23:59:59')->chunk(500, function ($users) use ($currency)  {
            foreach ($users as $user) {
                $wallet = Wallet::where('user_id', $user->id)->where('currency_id', $currency->id)->first();

                if($wallet) {
                    $wallet->balance_in_wallet = $wallet->balance_in_wallet + 25000;
                    $wallet->update();
                    $this->i++;
                }
            }
        });

        $this->info($this->i . ' wallets updated with the balance 25k of VITEX');

    }
}
