<?php

namespace Tests\Feature;

use App\Models\User;
use App\Models\Keruletek;
use App\Models\WcAdatok;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class MosdoTorlesTest extends TestCase
{
    use RefreshDatabase;

    public function test_admin_torolhet_mosdot()
    {
        // 1. Admin felhasználó
        $admin = User::factory()->create(['is_admin' => true]);

        // 2. Teszt mosdó
        $kerulet = Keruletek::factory()->create();
        $mosdo = WcAdatok::factory()->create(['kerulet_id' => $kerulet->id, 'felhasznalo_id' => $admin->id]);

        // 3. Token generálás és kérés küldés
        $response = $this->actingAs($admin, 'api')
            ->deleteJson("/api/mosdotorles/{$mosdo->id}");

        $response->assertStatus(200);
        $this->assertDatabaseMissing('wc_adatok', ['id' => $mosdo->id]);
    }

    public function test_nem_admin_nem_torolhet()
    {
        $user = User::factory()->create(['is_admin' => false]);
        $kerulet = Keruletek::factory()->create();
        $mosdo = WcAdatok::factory()->create(['kerulet_id' => $kerulet->id, 'felhasznalo_id' => $user->id]);

        $response = $this->actingAs($user, 'api')
            ->deleteJson("/api/mosdotorles/{$mosdo->id}");

        $response->assertStatus(403);
        $this->assertDatabaseHas('wc_adatok', ['id' => $mosdo->id]);
    }

    public function test_anonim_felhasznalo_nem_torolhet()
    {
        $kerulet = Keruletek::factory()->create();
        $user = User::factory()->create(['is_admin' => false]);
        $mosdo = WcAdatok::factory()->create(['kerulet_id' => $kerulet->id, 'felhasznalo_id' => $user->id]);

        $response = $this->deleteJson("/api/mosdotorles/{$mosdo->id}");

        $response->assertStatus(401);
    }
}
