<?php

namespace Tests\Feature\V3\RoadItemsProject;

use App\Models\Permission;
use App\Models\RoadItemsProject;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class SupervisorIndexTest extends TestCase
{
    use RefreshDatabase, WithFaker;
    /**
     * A basic feature test example.
     */
    public function test_user_should_have_show_road_item_supervise_cartable_permission(): void
    {
        $user = User::factory()->create();

        $response = $this->actingAs($user)->getJson(route('v3.road_items.supervisorIndex'));

        $response->assertForbidden();
    }
    public function test_user_cannot_access_authentication_to_supervisor_index(): void
    {
        $response = $this->getJson(route('v3.road_items.supervisorIndex'));

        $response->assertStatus(401);
    }


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

        RoadItemsProject::factory(10)->create();

        $response = $this->actingAs($user)->getJson(route('v3.road_items.supervisorIndex', [
            'size' => 10,
            'start' => 0,
            'sorting' => json_encode([]),
            'filters' => json_encode([]),
        ]));

        $response->assertOk();

        $response->assertJsonStructure([
            'data' => [
                '*' => [
                    "id",
                    "start_lat",
                    "start_lng",
                    "end_lat",
                    "end_lng",
                    "item",
                    "item_fa",
                    "sub_item_fa",
                    "sub_item_data",
                    "created_at",
                    "province_fa",
                    "unit_fa",
                    "status",
                    "status_fa",
                    "edarat_name",
                    "activity_date_time",
                    "can_supervise",
                ],
            ]
        ]);
    }
}
