<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\InstallerController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\AdminController;

Route::get('/', function () {
    return redirect()->route('admin.dashboard');
});

// Authentication Routes
Route::get('/admin/login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('/admin/login', [AuthController::class, 'login']);
Route::post('/admin/logout', [AuthController::class, 'logout'])->name('logout');

// Web App Admin Routes protected by auth & license
Route::prefix('admin')->name('admin.')->middleware(['auth', 'license'])->group(function () {
    Route::get('/dashboard', [AdminController::class, 'dashboard'])->name('dashboard');
});

Route::prefix('install')->name('install.')->group(function () {
    Route::get('/', [InstallerController::class, 'index'])->name('index');
    Route::post('/database', [InstallerController::class, 'database'])->name('database');
    Route::get('/license', [InstallerController::class, 'licenseForm'])->name('license_form');
    Route::post('/license', [InstallerController::class, 'validateLicense'])->name('license');
    Route::get('/admin', [InstallerController::class, 'adminForm'])->name('admin_form');
    Route::post('/admin', [InstallerController::class, 'createAdmin'])->name('admin');
    Route::get('/complete', [InstallerController::class, 'complete'])->name('complete');
});
