<?php
namespace App\Models;

use Core\Model;

class IncidentEvent extends Model
{
    protected static string $table = 'incident_events';
    protected static string $primaryKey = 'id';
    
    // Prevent the framework from auditing the event log itself (avoids bloat)
    protected static bool $auditable = false;
    
    /**
     * Fetch the human-readable timeline for a specific emergency.
     * Useful for the Admin Dashboard to reconstruct what happened and when.
     */
    public static function getIncidentTimeline(int $incidentId): array
    {
        $sql = "
            SELECT 
                e.*, 
                u.full_name as actor_name,
                u.role as actor_role
            FROM 
                incident_events e
            LEFT JOIN 
                users u ON e.actor_id = u.id
            WHERE 
                e.incident_id = ?
            ORDER BY 
                e.created_at DESC
        ";

        return self::fetchAll($sql, [$incidentId]);
    }
}