<?php

namespace App\Models\Concerns;

use App\Support\ActivityLog\ModelLabel;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;

trait InteractsWithActivityLog
{
    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logUnguarded()
            ->logOnlyDirty()
            ->dontLogEmptyChanges()
            ->logExcept([
                'password',
                'remember_token',
                'created_at',
                'updated_at',
                'deleted_at',
            ])
            ->setDescriptionForEvent(function (string $eventName): string {
                $label = ModelLabel::for(static::class);

                return match ($eventName) {
                    'created' => "{$label} dibuat",
                    'updated' => "{$label} diperbarui",
                    'deleted' => "{$label} dihapus",
                    default => "{$label} {$eventName}",
                };
            });
    }
}
