<?php

declare(strict_types=1);

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Route;
use Maestro\Core\Http\Controllers\PublicHomeController;
use Maestro\Core\Models\MaestroAppSetting;
use Tests\TestCase;

final class PublicHomeControllerTest extends TestCase
{
    use RefreshDatabase;

    public function test_root_mode_login_redirects_to_auth_login(): void
    {
        Route::get('/', PublicHomeController::class)->name('public.home');
        MaestroAppSetting::instance()->update([
            'public_page' => [
                'enabled' => true,
                'mode' => 'core_default',
                'root_mode' => 'login',
            ],
        ]);

        $this->get('/')->assertRedirect('/auth/login');
    }

    public function test_root_mode_dashboard_redirects_to_dashboard(): void
    {
        Route::get('/', PublicHomeController::class)->name('public.home');
        MaestroAppSetting::instance()->update([
            'public_page' => [
                'enabled' => true,
                'mode' => 'core_default',
                'root_mode' => 'dashboard',
            ],
        ]);

        $this->get('/')->assertRedirect('/dashboard');
    }

    public function test_root_mode_public_renders_core_view_when_enabled(): void
    {
        Route::get('/', PublicHomeController::class)->name('public.home');
        MaestroAppSetting::instance()->update([
            'public_page' => [
                'enabled' => true,
                'mode' => 'core_default',
                'root_mode' => 'public',
            ],
        ]);

        $this->get('/')
            ->assertOk()
            ->assertViewIs('maestro-core::public-home');
    }
}
