<?php

namespace App\Modules\Pilkades\Services;

use App\Models\User;
use App\Modules\Pilkades\Models\ActivityLog;

class ActivityLogService
{
    public function log(User $causer, string $description, ?object $subject = null, array $properties = []): ActivityLog
    {
        return ActivityLog::create([
            'causer_type' => $causer->getMorphClass(),
            'causer_id' => $causer->getKey(),
            'subject_type' => $subject ? $subject->getMorphClass() : $causer->getMorphClass(),
            'subject_id' => $subject ? $subject->getKey() : $causer->getKey(),
            'description' => $description,
            'desa_id' => $causer->desa_id,
            'properties' => $properties,
        ]);
    }
}
