<?php

declare(strict_types=1);

use App\Enums\Auth\ExtendedCrudPermission;
use App\Models\Auth\User;
use App\Models\Wiki\Video;
use Laravel\Sanctum\Sanctum;

use function Pest\Laravel\patch;

test('protected', function (): void {
    $video = Video::factory()->trashed()->createOne();

    $response = patch(route('api.video.restore', ['video' => $video]));

    $response->assertUnauthorized();
});

test('forbidden', function (): void {
    $video = Video::factory()->trashed()->createOne();

    $user = User::factory()->createOne();

    Sanctum::actingAs($user);

    $response = patch(route('api.video.restore', ['video' => $video]));

    $response->assertForbidden();
});

test('trashed', function (): void {
    $video = Video::factory()->createOne();

    $user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE->format(Video::class))->createOne();

    Sanctum::actingAs($user);

    $response = patch(route('api.video.restore', ['video' => $video]));

    $response->assertOk();
});

test('restored', function (): void {
    $video = Video::factory()->trashed()->createOne();

    $user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE->format(Video::class))->createOne();

    Sanctum::actingAs($user);

    $response = patch(route('api.video.restore', ['video' => $video]));

    $response->assertOk();
    $this->assertNotSoftDeleted($video);
});
