<?php

use App\Http\Controllers\ProfileController;
use App\Livewire\Activity;
use App\Livewire\Articles;
use App\Livewire\Channels;
use App\Livewire\Dashboard;
use App\Livewire\Feeds;
use App\Livewire\Onboarding;
use App\Livewire\Routes;
use App\Livewire\Settings;
use Illuminate\Support\Facades\Route;

// Redirect root to dashboard
Route::get('/', function () {
    return redirect()->route('dashboard');
});

// Onboarding routes (protected by auth, but need incomplete onboarding)
Route::middleware(['auth', 'onboarding.incomplete'])->group(function () {
    Route::get('/onboarding', Onboarding::class)->name('onboarding');
});

// Main app routes (protected by auth and require completed onboarding)
Route::middleware(['auth', 'onboarding.complete'])->group(function () {
    Route::get('/dashboard', Dashboard::class)->name('dashboard');
    Route::get('/articles', Articles::class)->name('articles');
    Route::get('/activity', Activity::class)->name('activity');
    Route::get('/feeds', Feeds::class)->name('feeds');
    Route::get('/channels', Channels::class)->name('channels');
    Route::get('/routes', Routes::class)->name('routes');
    Route::get('/settings', Settings::class)->name('settings');
});

// Profile routes (auth protected, no onboarding check needed)
Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

require __DIR__.'/auth.php';

Route::get('/health', function () {
    return response()->json(['status' => 'ok']);
});

Route::fallback(function () {
    return response()->json([
        'message' => 'Not found. The FFR interface is at /dashboard; API endpoints are under /api/v1.',
        'api_base' => '/api/v1',
    ], 404);
});
