<?php

namespace Tests\Feature\V3\RoadItemsProject;

use App\Models\LogList;
use App\Models\Permission;
use App\Models\RoadItemsProject;
use App\Models\User;
use App\Models\UserActivityLog;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use function Ramsey\Uuid\v3;

class RestoreTest extends TestCase
{
    use RefreshDatabase, WithFaker;

    public function test_user_should_have_show_road_item_supervise_restore_permission(): void
    {
        $user = User::factory()->create();
        $roadItem = RoadItemsProject::factory()->create();
        $response = $this->actingAs($user)->postJson(route('v3.road_items.restore', [$roadItem->id]));
        $response->assertForbidden();
    }
    public function test_user_cannot_access_authentication_restore(): void
    {
        $roadItem = RoadItemsProject::factory()->create();
        $response =$this->postJson(route('v3.road_items.restore', [$roadItem->id]));
        $response->assertStatus(401);

    }
    public function test_user_can_restore_road_item(): void
    {
        $user = User::factory()
            ->has(Permission::factory([
                'name' => 'restore-road-item'
            ]))
            ->create();

        $logList = LogList::factory()->create([
            'log_unique_code' => 1150,
        ]);
        UserActivityLog::factory()->create();

        $roadItem = RoadItemsProject::factory()->create([
            'status' => 1,
            'status_fa' => 'تایید شده',
            'supervisor_id' => $user->id,
            'supervisor_name' => $user->name,
            'supervisor_description' => 'تایید شده توسط تست',
        ]);

        $response = $this->actingAs($user)->postJson(route('v3.road_items.restore', [$roadItem->id]));

        $response->assertOk()
            ->assertJson([
                'message' => __('messages.successful'),
            ]);

        $this->assertDatabaseHas('road_items_projects', [
            'id' => $roadItem->id,
            'status' => 0,
            'status_fa' => 'در حال بررسی',
            'supervisor_id' => null,
            'supervisor_name' => null,
            'supervisor_description' => null,
            'supervising_time' => null,
        ]);
    }

}
