<?php

namespace Database\Factories;

use App\Enums\ActivityTypeEnum;
use App\Models\ActivityLog;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

/**
 * @extends Factory<ActivityLog>
 */
class ActivityLogFactory extends Factory
{
    protected $model = ActivityLog::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'type' => fake()->randomElement(ActivityTypeEnum::cases()),
            'message' => fake()->sentence(4),
            'context' => null,
            'subject_type' => null,
            'subject_id' => null,
            'logged_at' => now(),
        ];
    }

    public function type(ActivityTypeEnum $type): static
    {
        return $this->state(['type' => $type]);
    }

    public function loggedAt(Carbon $loggedAt): static
    {
        return $this->state(['logged_at' => $loggedAt]);
    }

    public function forSubject(Model $subject): static
    {
        return $this->state([
            'subject_type' => $subject->getMorphClass(),
            'subject_id' => $subject->getKey(),
        ]);
    }
}
