<?php

use App\Jobs\AuditAndFailedJobReportJob;
use App\Jobs\AutoCollectTreasuryDepositsJob;
use App\Jobs\AutoSettleMerchantBalancesJob;
use App\Jobs\DispatchOpenInvoicePollingJob;
use App\Jobs\ExpirePaymentsJob;
use App\Jobs\FindUnallocatedDepositsJob;
use App\Jobs\MerchantBalanceStatementSnapshotJob;
use App\Jobs\OperationsMonitorJob;
use App\Jobs\ProviderHealthCheckJob;
use App\Jobs\PublishOutboxMessagesJob;
use App\Jobs\ReconcileAssetJob;
use App\Jobs\ReconcileWalletJob;
use App\Jobs\RefreshRateSourceHealthJob;
use App\Jobs\RefreshStuckConfirmingTransactionsJob;
use App\Jobs\RetryDueMerchantWebhooksJob;
use App\Jobs\SyncOpenPayoutsJob;
use App\Jobs\SyncTreasuryDepositBalancesJob;
use App\Models\Asset;
use Illuminate\Support\Facades\Schedule;

Schedule::job(new ExpirePaymentsJob)->everyMinute()->name('expire-payments')->withoutOverlapping()->onOneServer();
Schedule::job(new RetryDueMerchantWebhooksJob)->everyMinute()->name('retry-due-merchant-webhooks')->withoutOverlapping()->onOneServer();
Schedule::job(new RefreshStuckConfirmingTransactionsJob)->everyMinute()->name('refresh-stuck-confirming-transactions')->withoutOverlapping()->onOneServer();
Schedule::job(new SyncOpenPayoutsJob)->everyFiveMinutes()->name('sync-open-payouts')->withoutOverlapping()->onOneServer();
Schedule::job(new DispatchOpenInvoicePollingJob(config('gateway.environment')))->everyMinute()->name('dispatch-open-invoice-polling')->withoutOverlapping()->onOneServer();
Schedule::job(new SyncTreasuryDepositBalancesJob(config('gateway.environment')))->everyMinute()->name('sync-treasury-deposit-balances')->withoutOverlapping()->onOneServer();
Schedule::job(new AutoCollectTreasuryDepositsJob(config('gateway.environment')))->everyMinute()->name('auto-collect-treasury-deposits')->withoutOverlapping()->onOneServer();
Schedule::job(new ProviderHealthCheckJob)->everyFiveMinutes()->name('provider-health-check')->withoutOverlapping()->onOneServer();
Schedule::call(fn () => Asset::where('enabled', true)->each(fn ($asset) => ReconcileAssetJob::dispatch($asset->id, config('gateway.environment'))->onQueue('reconciliation')))->hourly()->name('reconcile-enabled-assets')->withoutOverlapping()->onOneServer();
Schedule::job(new FindUnallocatedDepositsJob)->hourly()->name('find-unallocated-deposits')->withoutOverlapping()->onOneServer();
Schedule::job(new RefreshRateSourceHealthJob)->hourly()->name('refresh-rate-source-health')->withoutOverlapping()->onOneServer();
Schedule::call(fn () => Asset::where('enabled', true)->each(fn () => ReconcileWalletJob::dispatch()->onQueue('reconciliation')))->dailyAt('01:00')->name('reconcile-wallets')->withoutOverlapping()->onOneServer();
Schedule::job(new MerchantBalanceStatementSnapshotJob)->dailyAt('01:15')->name('merchant-balance-statement-snapshot')->withoutOverlapping()->onOneServer();
Schedule::job(new AutoSettleMerchantBalancesJob(config('gateway.environment')))->dailyAt('02:00')->name('auto-settle-merchant-balances')->withoutOverlapping()->onOneServer();
Schedule::job(new AuditAndFailedJobReportJob)->dailyAt('01:30')->name('audit-and-failed-job-report')->withoutOverlapping()->onOneServer();
Schedule::job(new PublishOutboxMessagesJob)->everyMinute()->name('publish-outbox-messages')->withoutOverlapping()->onOneServer();
Schedule::job(new OperationsMonitorJob)->everyFiveMinutes()->name('operations-monitor')->withoutOverlapping()->onOneServer();

