<?php

namespace App\Filament\Resources\Pages;

use App\Services\Audit\SuperAdminAuditLogger;
use Filament\Resources\Pages\EditRecord;

class AuditedEditRecord extends EditRecord
{
    protected function afterSave(): void
    {
        $changed = array_keys($this->record->getChanges());

        if ($changed === []) {
            return;
        }

        app(SuperAdminAuditLogger::class)->recordModelMutation(
            'updated',
            $this->record,
            SuperAdminAuditLogger::fieldsMetadata($changed ?: $this->form->getState()),
            static::class
        );
    }
}
