<?php

namespace Tests\Feature\V2\Dashboard\RoadItemsProject;

use App\Models\City;
use App\Models\EdarateOstani;
use App\Models\EdarateShahri;
use App\Models\InfoItem;
use App\Models\LogList;
use App\Models\ObservedItem;
use App\Models\Permission;
use App\Models\Province;
use App\Models\RoadItemsProject;
use App\Models\User;
use App\Models\UserActivityLog;
use Illuminate\Foundation\Testing\RefreshDataBase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Tests\TestCase;

class RestoreTest extends TestCase
{
    use RefreshDataBase;
    /**
     * A basic feature test example.
     */
    public function test_user_should_have_restore_road_item_permission(): void
    {
        $user = User::factory()->create();

        $roadItem = RoadItemsProject::factory()->create();

        $response = $this->actingAs($user)->postJson("/v2/road_items/supervisor/cartable/restore/{$roadItem->id}");

        $response->assertForbidden();
    }

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

        $roadItem = RoadItemsProject::factory()->create([
            'status' => 0
        ]);

        $response = $this->actingAs($user)->postJson("/v2/road_items/supervisor/cartable/restore/{$roadItem->id}");

        $response->assertStatus(400)
            ->assertExactJson([
                'message' => 'امکان بازگردانی وضعیت این فعالیت وجود ندارد!'
            ]);
    }

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

        $roadItem = RoadItemsProject::factory()->create([
            'status' => 1
        ]);

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

        $userActivityLog = UserActivityLog::factory()->create();

        $response = $this->actingAs($user)->postJson("/v2/road_items/supervisor/cartable/restore/{$roadItem->id}");

        $response->assertOk()
            ->assertExactJson([
                'status' => 'succeed',
            ]);

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