<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        // Financial Events
        \App\Domain\Financial\Events\InvoiceCreated::class => [
            \App\Domain\Financial\Listeners\SendInvoiceNotification::class,
        ],
        \App\Domain\Financial\Events\InvoicePaid::class => [
            \App\Domain\Financial\Listeners\ActivateEnrollmentOnPayment::class,
        ],
        \App\Domain\Financial\Events\InvoiceOverdue::class => [
            \App\Domain\Financial\Listeners\SendOverdueReminder::class,
        ],
        \App\Domain\Financial\Events\InvoiceSent::class => [
            \App\Domain\Financial\Listeners\SendInvoiceSentNotification::class,
        ],
        \App\Domain\Financial\Events\InvoiceCancelled::class => [
            \App\Domain\Financial\Listeners\SendInvoiceCancelledNotification::class,
        ],
        \App\Domain\Financial\Events\InstallmentOverdue::class => [
            \App\Domain\Financial\Listeners\NotifyInstallmentDue::class,
        ],
        \App\Domain\Financial\Events\PaymentReceived::class => [
            \App\Domain\Financial\Listeners\SendPaymentConfirmation::class,
            \App\Domain\Financial\Listeners\SendPaymentNotification::class,
            \App\Domain\Financial\Listeners\UpdateCashSessionTotals::class,
        ],
        \App\Domain\Financial\Events\PaymentPlanDefaulted::class => [
            \App\Domain\Financial\Listeners\SendPaymentPlanDefaultedNotification::class,
        ],
        \App\Domain\Financial\Events\WalletDeposited::class => [
            \App\Domain\Financial\Listeners\SendWalletDepositNotification::class,
        ],
        \App\Domain\Financial\Events\WalletFrozen::class => [
            \App\Domain\Financial\Listeners\SendWalletFrozenNotification::class,
        ],
        \App\Domain\Financial\Events\CashSessionClosed::class => [
            \App\Domain\Financial\Listeners\SendCashSessionClosedNotification::class,
        ],

        // Training Events
        \App\Domain\Training\Events\EnrollmentCreated::class => [
            \App\Domain\Training\Listeners\UpdateGroupCount::class,
            \App\Domain\Training\Listeners\GenerateAttendanceRecords::class,
        ],
        \App\Domain\Training\Events\EnrollmentCancelled::class => [
            \App\Domain\Training\Listeners\UpdateGroupCount::class,
            \App\Domain\Training\Listeners\RemoveAttendanceRecords::class,
            \App\Domain\Training\Listeners\ProcessWaitlist::class,
        ],
        \App\Domain\Training\Events\EnrollmentCompleted::class => [
            \App\Domain\Training\Listeners\SendEnrollmentCompletedNotification::class,
        ],
        \App\Domain\Training\Events\EnrollmentTransferred::class => [
            \App\Domain\Training\Listeners\HandleEnrollmentTransfer::class,
        ],
        \App\Domain\Training\Events\SessionCreated::class => [
            \App\Domain\Training\Listeners\CreateAutoReservation::class,
        ],
        \App\Domain\Training\Events\SessionCancelled::class => [
            \App\Domain\Training\Listeners\NotifySessionCancellation::class,
            \App\Domain\Training\Listeners\CancelLinkedReservation::class,
            \App\Domain\HR\Listeners\HandleSessionCancelled::class,
        ],
        \App\Domain\Training\Events\SessionCompleted::class => [
            \App\Domain\Training\Listeners\SendSessionCompletedNotification::class,
        ],
        \App\Domain\Training\Events\WaitlistSpotAvailable::class => [
            \App\Domain\Training\Listeners\NotifyWaitlistSpot::class,
        ],
        \App\Domain\Training\Events\ParticipantRegistered::class => [
            \App\Domain\Training\Listeners\SendParticipantRegisteredNotification::class,
        ],
        \App\Domain\Training\Events\ParticipantStatusChanged::class => [
            \App\Domain\Training\Listeners\SendParticipantStatusChangedNotification::class,
        ],
        \App\Domain\Training\Events\EvaluationShared::class => [
            \App\Domain\Training\Listeners\SendEvaluationSharedNotification::class,
        ],

        // Attendance Events
        \App\Domain\Attendance\Events\AttendanceMarked::class => [
            \App\Domain\HR\Listeners\GenerateTrainerCompensation::class,
        ],
        \App\Domain\Attendance\Events\ParticipantAbsent::class => [
            \App\Domain\Attendance\Listeners\NotifyGuardianOfAbsence::class,
        ],
        \App\Domain\Attendance\Events\AttendanceThresholdBreached::class => [
            \App\Domain\Attendance\Listeners\NotifyThresholdBreach::class,
            \App\Domain\Attendance\Listeners\SuspendOnThreshold::class,
        ],

        // Facility Events
        \App\Domain\Facility\Events\SpaceReservationCreated::class => [],
        \App\Domain\Facility\Events\FacilityStatusChanged::class => [
            \App\Domain\Facility\Listeners\CancelReservationsOnMaintenance::class,
        ],

        // Inventory Events
        \App\Domain\Inventory\Events\ProductLowStock::class => [
            \App\Domain\Inventory\Listeners\NotifyAdminLowStock::class,
        ],
        \App\Domain\Inventory\Events\InventoryMovementCreated::class => [
            \App\Domain\Inventory\Listeners\CheckLowStockThreshold::class,
        ],
        \App\Domain\Inventory\Events\PurchaseOrderReceived::class => [
            \App\Domain\Inventory\Listeners\CreateReceivingMovements::class,
        ],
        \App\Domain\Inventory\Events\StockCountCompleted::class => [
            \App\Domain\Inventory\Listeners\ProcessCountAdjustments::class,
        ],
        \App\Domain\Inventory\Events\KitAssembled::class => [
            \App\Domain\Inventory\Listeners\DeductKitComponents::class,
        ],

        // Scheduling Events
        \App\Domain\Scheduling\Events\AssignmentCreated::class => [
            \App\Domain\Scheduling\Listeners\GenerateTrainerAttendance::class,
        ],
        \App\Domain\Scheduling\Events\AssignmentEnded::class => [
            \App\Domain\Scheduling\Listeners\RemoveTrainerAttendance::class,
        ],

        // Participant Events
        \App\Domain\Participant\Events\ParticipantSuspended::class => [
            \App\Domain\Participant\Listeners\SendParticipantSuspendedNotification::class,
        ],
        \App\Domain\Participant\Events\ParticipantFrozen::class => [
            \App\Domain\Participant\Listeners\SendParticipantFrozenNotification::class,
        ],

        // POS Events
        \App\Domain\POS\Events\POSTransactionCompleted::class => [
            \App\Domain\POS\Listeners\SendPOSReceiptNotification::class,
        ],
    ];

    public function shouldDiscoverEvents(): bool
    {
        return false;
    }
}
