<?php

use App\Enums\TimelineStatus;
use App\Models\Timeline;
use App\Models\TimelineUpdate;
use App\Models\User;

test('timeline belongs to user', function () {
    $user = User::factory()->create();
    $timeline = Timeline::factory()->create(['user_id' => $user->id]);

    expect($timeline->user)->toBeInstanceOf(User::class)
        ->and($timeline->user->id)->toBe($user->id);
});

test('timeline has correct status cast', function () {
    $timeline = Timeline::factory()->create(['status' => 'active']);

    expect($timeline->status)->toBeInstanceOf(TimelineStatus::class)
        ->and($timeline->status)->toBe(TimelineStatus::Active);
});

test('timeline has many updates', function () {
    $timeline = Timeline::factory()->create();
    TimelineUpdate::factory()->count(3)->create(['timeline_id' => $timeline->id]);

    expect($timeline->updates)->toHaveCount(3)
        ->and($timeline->updates->first())->toBeInstanceOf(TimelineUpdate::class);
});

test('timeline update belongs to timeline', function () {
    $timeline = Timeline::factory()->create();
    $update = TimelineUpdate::factory()->create(['timeline_id' => $timeline->id]);

    expect($update->timeline)->toBeInstanceOf(Timeline::class)
        ->and($update->timeline->id)->toBe($timeline->id);
});

test('timeline update belongs to admin', function () {
    $admin = User::factory()->admin()->create();
    $update = TimelineUpdate::factory()->create(['admin_id' => $admin->id]);

    expect($update->admin)->toBeInstanceOf(User::class)
        ->and($update->admin->id)->toBe($admin->id);
});
