<?php

namespace App\Observers;

use App\Models\ActivityLog;
use App\Services\ActivityLogger;
use Illuminate\Database\Eloquent\Model;

class ActivityLogObserver
{
    public function created(Model $model): void
    {
        if ($this->shouldSkip($model)) {
            return;
        }

        ActivityLogger::recordModelEvent($model, 'created');
    }

    public function updated(Model $model): void
    {
        if ($this->shouldSkip($model)) {
            return;
        }

        ActivityLogger::recordModelEvent($model, 'updated');
    }

    public function deleted(Model $model): void
    {
        if ($this->shouldSkip($model)) {
            return;
        }

        ActivityLogger::recordModelEvent($model, 'deleted');
    }

    private function shouldSkip(Model $model): bool
    {
        return $model instanceof ActivityLog;
    }
}
