<?php
namespace App\Models;

use Core\Model;

/**
 * AuditLog Model
 * Matches the automatic logging system built into your custom Core\Model.
 */
class AuditLog extends Model
{
    protected static string $table = 'audit_logs';
    
    // CRITICAL: Must be false to prevent the Model from auditing its own audits!
    protected static bool $auditable = false; 

    public static function getIncidentTimeline(int $incidentId): array
    {
        $sql = "
            SELECT 
                a.*, 
                u.full_name as actor_name,
                u.role as actor_role
            FROM 
                audit_logs a
            LEFT JOIN 
                users u ON a.changed_by = u.id
            WHERE 
                a.record_id = ? AND a.table_name = 'incidents'
            ORDER BY 
                a.created_at DESC
        ";

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