<?php

namespace Tests\Feature;

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

class DemoLoginModuleTest extends TestCase
{
    use RefreshDatabase;

    public function test_enabled_demo_module_shows_buttons_and_logs_in_demo_admin(): void
    {
        Setting::create(['key' => 'demo_login_enabled', 'value' => '1']);

        User::create([
            'name' => 'Admin Demo',
            'email' => 'admin@mgg.test',
            'password' => 'password',
            'role' => 'admin',
        ]);
        User::create([
            'name' => 'GTS Client Demo',
            'email' => 'gts-client@mgg.test',
            'password' => 'password',
            'role' => 'gts_client',
        ]);

        $this->get('/login')
            ->assertOk()
            ->assertSee('Demo Login Module')
            ->assertSee('Admin Demo Login')
            ->assertSee('GTS Client Demo');

        $this->post('/demo-login/admin')->assertRedirect('/admin/portal');
        $this->assertAuthenticated();
    }

    public function test_disabled_demo_module_hides_buttons_and_blocks_demo_route(): void
    {
        Setting::create(['key' => 'demo_login_enabled', 'value' => '0']);

        $this->get('/login')
            ->assertOk()
            ->assertDontSee('Demo Login Module')
            ->assertDontSee('Admin Demo Login');

        $this->post('/demo-login/admin')->assertNotFound();
    }
}
