<?php

namespace Tests\Feature\V3\Azmayesh;

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

class DeleteTest extends TestCase
{
    use RefreshDatabase;
    /**
     * A basic feature test example.
     */
    public function test_user_should_have_azmayesh_management_permission(): void
    {
        $user = User::factory()->create();
        $azmayesh = Azmayesh::factory()->create();

        $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.delete', [$azmayesh->id]));

        $response->assertForbidden();
    }

    public function test_user_can_delete_azmayesh(): void
    {
        $user = User::factory()
            ->has(Permission::factory([
                'name' => 'azmayesh-management'
            ]))
            ->create();

        $azmayesh = Azmayesh::factory()->create();

        $response = $this->actingAs($user)->postJson(route('v3.azmayeshes.delete', [$azmayesh->id]));

        $response->assertOk();

        $this->assertDatabaseMissing('azmayeshes', [
            'lat' => $azmayesh->lat,
            'lng' => $azmayesh->lng,
            'azmayesh_type_id' => $azmayesh->azmayesh_type_id,
            'azmayesh_type_name' => $azmayesh->azmayesh_type_name,
            'request_date' => $azmayesh->request_date,
            'report_date' => $azmayesh->report_date,
            'request_number' => $azmayesh->request_number,
            'employer' => $azmayesh->employer,
            'contractor' => $azmayesh->contractor,
            'work_number' => $azmayesh->work_number,
            'project_name' => $azmayesh->project_name,
            'consultant' => $azmayesh->consultant,
            'applicant' => $azmayesh->applicant,
            'province_id' => $azmayesh->province_id,
            'province_name' => $azmayesh->province_name,
        ]);
    }
}
