<?php

namespace App\Jobs;

use App\Application\Services\Treasury\TreasuryWalletService;
use App\Models\Asset;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

final class SyncTreasuryDepositBalancesJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function __construct(public string $environment)
    {
        $this->onQueue('reconciliation');
    }

    public function handle(TreasuryWalletService $treasury): void
    {
        Asset::where('enabled', true)
            ->where('deposit_enabled', true)
            ->whereNotNull('contract_address')
            ->each(function (Asset $asset) use ($treasury) {
                $treasury->syncDepositAddressBalances($asset, $this->environment);
            });
    }
}
