<?php

namespace App\Domain\Attendance\Listeners;

use App\Domain\Attendance\Events\AttendanceThresholdBreached;
use App\Domain\Participant\Services\ParticipantService;
use App\Domain\Shared\Services\SettingsService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;

class SuspendOnThreshold implements ShouldQueue
{
    public function __construct(
        private ParticipantService $participantService,
        private SettingsService $settings,
    ) {}

    public function handle(AttendanceThresholdBreached $event): void
    {
        // Never auto-suspend — participants stay enrolled regardless of attendance.
        // Only admin can change participant status manually.
        Log::info('Attendance threshold breached (no auto-action taken)', [
            'participant_id' => $event->participant->id,
            'rate' => $event->rate ?? null,
        ]);
    }

    public function failed(AttendanceThresholdBreached $event, \Throwable $exception): void
    {
        Log::critical('SuspendOnThreshold PERMANENTLY FAILED', [
            'participant_id' => $event->participant->id,
            'error' => $exception->getMessage(),
        ]);
    }
}
