<?php

namespace App\Models\Concerns;

use App\Services\AuditLogService;

trait Auditable
{
    public static function bootAuditable(): void
    {
        static::created(function ($model) {
            app(AuditLogService::class)->record('created', $model, [], $model->getAttributes());
        });

        static::updated(function ($model) {
            app(AuditLogService::class)->record('updated', $model, $model->getOriginal(), $model->getChanges());
        });

        static::deleted(function ($model) {
            app(AuditLogService::class)->record('deleted', $model, $model->getOriginal(), []);
        });
    }
}
