<?php

use App\Http\Controllers\Api\Admin\AnnouncementController as AdminAnnouncementController;
use App\Http\Controllers\Api\Admin\AuthController;
use App\Http\Controllers\Api\Admin\BlockController as AdminBlockController;
use App\Http\Controllers\Api\Admin\CategoryController as AdminCategoryController;
use App\Http\Controllers\Api\Admin\CommentController as AdminCommentController;
use App\Http\Controllers\Api\Admin\CourseBlockController as AdminCourseBlockController;
use App\Http\Controllers\Api\Admin\CourseController as AdminCourseController;
use App\Http\Controllers\Api\Admin\FaqController as AdminFaqController;
use App\Http\Controllers\Api\Admin\GuideCardController as AdminGuideCardController;
use App\Http\Controllers\Api\Admin\HeroSlideController as AdminHeroSlideController;
use App\Http\Controllers\Api\Admin\LeadController as AdminLeadController;
use App\Http\Controllers\Api\Admin\MenuController as AdminMenuController;
use App\Http\Controllers\Api\Admin\PageController as AdminPageController;
use App\Http\Controllers\Api\Admin\PreviewController as AdminPreviewController;
use App\Http\Controllers\Api\Admin\RoleController;
use App\Http\Controllers\Api\Admin\ScheduleController as AdminScheduleController;
use App\Http\Controllers\Api\Admin\SettingController as AdminSettingController;
use App\Http\Controllers\Api\Admin\StoryController as AdminStoryController;
use App\Http\Controllers\Api\Admin\UploadController;
use App\Http\Controllers\Api\Admin\UserController;
use App\Http\Controllers\Api\V1\AnnouncementController;
use App\Http\Controllers\Api\V1\CategoryController;
use App\Http\Controllers\Api\V1\CommentController;
use App\Http\Controllers\Api\V1\CourseController;
use App\Http\Controllers\Api\V1\FaqController;
use App\Http\Controllers\Api\V1\GuideCardController;
use App\Http\Controllers\Api\V1\HeroSlideController;
use App\Http\Controllers\Api\V1\LeadController;
use App\Http\Controllers\Api\V1\MenuController;
use App\Http\Controllers\Api\V1\PageController;
use App\Http\Controllers\Api\V1\PreviewController;
use App\Http\Controllers\Api\V1\ScheduleController;
use App\Http\Controllers\Api\V1\SettingController;
use App\Http\Controllers\Api\V1\SitemapController;
use App\Http\Controllers\Api\V1\StoryController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Public API Routes (v1)
|--------------------------------------------------------------------------
*/
Route::prefix('v1')->group(function () {
    // Categories
    Route::get('categories', [CategoryController::class, 'index']);
    Route::get('categories/{slug}', [CategoryController::class, 'show']);

    // Courses
    Route::get('courses', [CourseController::class, 'index']);
    Route::get('courses/{slug}', [CourseController::class, 'show']);

    // Schedules
    Route::get('schedules', [ScheduleController::class, 'index']);
    Route::get('schedules/upcoming', [ScheduleController::class, 'upcoming']);
    Route::get('schedules/{id}', [ScheduleController::class, 'show']);

    // Announcements
    Route::get('announcements', [AnnouncementController::class, 'index']);
    Route::get('announcements/{slug}', [AnnouncementController::class, 'show']);

    // Hero Slides
    Route::get('hero-slides', [HeroSlideController::class, 'index']);

    // Leads (public form submission)
    Route::post('leads', [LeadController::class, 'store'])->middleware('throttle:leads');

    // Comments (public submission)
    Route::get('comments/{type}/{id}', [CommentController::class, 'index']);
    Route::post('comments', [CommentController::class, 'store'])->middleware('throttle:comments');

    // Menus
    Route::get('menus/{location}', [MenuController::class, 'index']);

    // FAQs
    Route::get('faqs', [FaqController::class, 'index']);
    Route::get('faqs/{category}', [FaqController::class, 'index']);

    // Guide Cards
    Route::get('guide-cards', [GuideCardController::class, 'index']);

    // Settings
    Route::get('settings', [SettingController::class, 'index']);
    Route::get('settings/{group}', [SettingController::class, 'show']);

    // Stories
    Route::get('stories', [StoryController::class, 'index']);

    // Pages
    Route::get('pages/{slug}', [PageController::class, 'show']);

    // Preview (public — Next.js server-side fetch)
    Route::get('preview/{token}', [PreviewController::class, 'show']);

    // Sitemap
    Route::get('sitemap-data', [SitemapController::class, 'index']);
});

/*
|--------------------------------------------------------------------------
| Admin API Routes (Sanctum Auth)
|--------------------------------------------------------------------------
*/
Route::prefix('admin')->group(function () {
    // Auth (public)
    Route::post('login', [AuthController::class, 'login']);

    // Protected routes
    Route::middleware('auth:sanctum')->group(function () {
        // Auth
        Route::get('me', [AuthController::class, 'me']);
        Route::post('logout', [AuthController::class, 'logout']);

        // Upload
        Route::post('uploads', [UploadController::class, 'store']);

        // Categories
        Route::apiResource('categories', AdminCategoryController::class);

        // Courses
        Route::apiResource('courses', AdminCourseController::class);

        // Course Blocks
        Route::post('courses/{course}/blocks/reorder', [AdminCourseBlockController::class, 'reorder']);
        Route::apiResource('courses.blocks', AdminCourseBlockController::class);

        // Schedules
        Route::apiResource('schedules', AdminScheduleController::class);

        // Announcements
        Route::apiResource('announcements', AdminAnnouncementController::class);

        // Hero Slides
        Route::apiResource('hero-slides', AdminHeroSlideController::class);

        // Leads
        Route::apiResource('leads', AdminLeadController::class)->except(['store']);

        // Menus
        Route::post('menus/reorder', [AdminMenuController::class, 'reorder']);
        Route::apiResource('menus', AdminMenuController::class);

        // Comments
        Route::apiResource('comments', AdminCommentController::class)->except(['store']);

        // FAQs
        Route::apiResource('faqs', AdminFaqController::class);

        // Guide Cards
        Route::apiResource('guide-cards', AdminGuideCardController::class);

        // Settings
        Route::get('settings', [AdminSettingController::class, 'index']);
        Route::get('settings/group/{group}', [AdminSettingController::class, 'group']);
        Route::put('settings', [AdminSettingController::class, 'update']);
        Route::post('settings/clear-cache', [AdminSettingController::class, 'clearCache']);

        // Pages
        Route::apiResource('pages', AdminPageController::class);

        // Page Blocks
        Route::post('pages/{page}/blocks/reorder', [AdminBlockController::class, 'reorder']);
        Route::apiResource('pages.blocks', AdminBlockController::class);

        // Stories
        Route::apiResource('stories', AdminStoryController::class);

        // Preview
        Route::post('preview', [AdminPreviewController::class, 'store']);
        Route::delete('preview/{token}', [AdminPreviewController::class, 'destroy']);

        // Users
        Route::apiResource('users', UserController::class);

        // Roles & Permissions
        Route::get('permissions', [RoleController::class, 'permissions']);
        Route::apiResource('roles', RoleController::class);
    });
});
