<?php

use Illuminate\Support\Facades\Route;

// ─────────────────────────────────────────────────────────
// FRONTEND ROUTES
// ─────────────────────────────────────────────────────────

Route::get('/', [\App\Http\Controllers\HomeController::class, 'index'])->name('home');

// Products
Route::get('/products', [\App\Http\Controllers\ProductPageController::class, 'index'])->name('products');
Route::get('/products/{slug}', [\App\Http\Controllers\ProductPageController::class, 'show'])->name('product.show');

// Solutions
Route::get('/solutions', [\App\Http\Controllers\SolutionPageController::class, 'index'])->name('solutions');
Route::get('/solutions/{slug}', [\App\Http\Controllers\SolutionPageController::class, 'show'])->name('solution.show');

// Case Studies
Route::get('/case-studies', [\App\Http\Controllers\CaseStudyPageController::class, 'index'])->name('case-studies');
Route::get('/case-studies/{slug}', [\App\Http\Controllers\CaseStudyPageController::class, 'show'])->name('case-study.show');

// Resources
Route::get('/resources', [\App\Http\Controllers\ResourcePageController::class, 'index'])->name('resources');

// Careers
Route::get('/careers', [\App\Http\Controllers\CareerPageController::class, 'index'])->name('careers');
Route::post('/careers/apply', [\App\Http\Controllers\CareerPageController::class, 'apply'])->name('career.apply');

// About & Contact
Route::get('/about', [\App\Http\Controllers\AboutPageController::class, 'index'])->name('about');
Route::get('/contact', [\App\Http\Controllers\ContactPageController::class, 'index'])->name('contact');

// Enquiry form (shared by contact, product, solution pages)
Route::post('/enquiry', [\App\Http\Controllers\EnquiryController::class, 'store'])->name('enquiry.store');

// ─────────────────────────────────────────────────────────
// ADMIN AUTH ROUTES (no middleware)
// ─────────────────────────────────────────────────────────

Route::prefix('admin')->name('admin.')->group(function () {

    Route::get('/login', [\App\Http\Controllers\Auth\AdminAuthController::class, 'showLogin'])->name('login');
    Route::post('/login', [\App\Http\Controllers\Auth\AdminAuthController::class, 'login'])->name('login.post');
    Route::post('/logout', [\App\Http\Controllers\Auth\AdminAuthController::class, 'logout'])->name('logout');

    // ─────────────────────────────────────────────────────
    // ADMIN PROTECTED ROUTES
    // ─────────────────────────────────────────────────────

    Route::middleware([\App\Http\Middleware\AdminMiddleware::class])->group(function () {

        // Dashboard
        Route::get('/', [\App\Http\Controllers\Admin\DashboardController::class, 'index'])->name('dashboard');

        // Products
        Route::get('/products', [\App\Http\Controllers\Admin\ProductController::class, 'index'])->name('products.index');
        Route::get('/products/create', [\App\Http\Controllers\Admin\ProductController::class, 'create'])->name('products.create');
        Route::post('/products', [\App\Http\Controllers\Admin\ProductController::class, 'store'])->name('products.store');
        Route::get('/products/{product}/edit', [\App\Http\Controllers\Admin\ProductController::class, 'edit'])->name('products.edit');
        Route::put('/products/{product}', [\App\Http\Controllers\Admin\ProductController::class, 'update'])->name('products.update');
        Route::delete('/products/{product}', [\App\Http\Controllers\Admin\ProductController::class, 'destroy'])->name('products.destroy');

        // Solutions
        Route::get('/solutions', [\App\Http\Controllers\Admin\SolutionController::class, 'index'])->name('solutions.index');
        Route::get('/solutions/create', [\App\Http\Controllers\Admin\SolutionController::class, 'create'])->name('solutions.create');
        Route::post('/solutions', [\App\Http\Controllers\Admin\SolutionController::class, 'store'])->name('solutions.store');
        Route::get('/solutions/{solution}/edit', [\App\Http\Controllers\Admin\SolutionController::class, 'edit'])->name('solutions.edit');
        Route::put('/solutions/{solution}', [\App\Http\Controllers\Admin\SolutionController::class, 'update'])->name('solutions.update');
        Route::delete('/solutions/{solution}', [\App\Http\Controllers\Admin\SolutionController::class, 'destroy'])->name('solutions.destroy');

        // Case Studies
        Route::get('/case-studies', [\App\Http\Controllers\Admin\CaseStudyController::class, 'index'])->name('case-studies.index');
        Route::get('/case-studies/create', [\App\Http\Controllers\Admin\CaseStudyController::class, 'create'])->name('case-studies.create');
        Route::post('/case-studies', [\App\Http\Controllers\Admin\CaseStudyController::class, 'store'])->name('case-studies.store');
        Route::get('/case-studies/{caseStudy}/edit', [\App\Http\Controllers\Admin\CaseStudyController::class, 'edit'])->name('case-studies.edit');
        Route::put('/case-studies/{caseStudy}', [\App\Http\Controllers\Admin\CaseStudyController::class, 'update'])->name('case-studies.update');
        Route::delete('/case-studies/{caseStudy}', [\App\Http\Controllers\Admin\CaseStudyController::class, 'destroy'])->name('case-studies.destroy');

        // Resources
        Route::get('/resources', [\App\Http\Controllers\Admin\ResourceController::class, 'index'])->name('resources.index');
        Route::get('/resources/create', [\App\Http\Controllers\Admin\ResourceController::class, 'create'])->name('resources.create');
        Route::post('/resources', [\App\Http\Controllers\Admin\ResourceController::class, 'store'])->name('resources.store');
        Route::get('/resources/{resource}/edit', [\App\Http\Controllers\Admin\ResourceController::class, 'edit'])->name('resources.edit');
        Route::put('/resources/{resource}', [\App\Http\Controllers\Admin\ResourceController::class, 'update'])->name('resources.update');
        Route::delete('/resources/{resource}', [\App\Http\Controllers\Admin\ResourceController::class, 'destroy'])->name('resources.destroy');

        // Jobs
        Route::get('/jobs', [\App\Http\Controllers\Admin\JobController::class, 'index'])->name('jobs.index');
        Route::get('/jobs/create', [\App\Http\Controllers\Admin\JobController::class, 'create'])->name('jobs.create');
        Route::post('/jobs', [\App\Http\Controllers\Admin\JobController::class, 'store'])->name('jobs.store');
        Route::get('/jobs/{job}/edit', [\App\Http\Controllers\Admin\JobController::class, 'edit'])->name('jobs.edit');
        Route::put('/jobs/{job}', [\App\Http\Controllers\Admin\JobController::class, 'update'])->name('jobs.update');
        Route::delete('/jobs/{job}', [\App\Http\Controllers\Admin\JobController::class, 'destroy'])->name('jobs.destroy');

        // Enquiries
        Route::get('/enquiries', [\App\Http\Controllers\Admin\EnquiryController::class, 'index'])->name('enquiries.index');
        Route::get('/enquiries/{enquiry}', [\App\Http\Controllers\Admin\EnquiryController::class, 'show'])->name('enquiries.show');
        Route::post('/enquiries/{enquiry}/status', [\App\Http\Controllers\Admin\EnquiryController::class, 'updateStatus'])->name('enquiries.status');
        Route::delete('/enquiries/{enquiry}', [\App\Http\Controllers\Admin\EnquiryController::class, 'destroy'])->name('enquiries.destroy');

        // CV Applications
        Route::get('/applications', [\App\Http\Controllers\Admin\ApplicationController::class, 'index'])->name('applications.index');
        Route::get('/applications/{application}', [\App\Http\Controllers\Admin\ApplicationController::class, 'show'])->name('applications.show');
        Route::post('/applications/{application}/status', [\App\Http\Controllers\Admin\ApplicationController::class, 'updateStatus'])->name('applications.status');
        Route::delete('/applications/{application}', [\App\Http\Controllers\Admin\ApplicationController::class, 'destroy'])->name('applications.destroy');

        // Settings — Site
        Route::get('/settings', [\App\Http\Controllers\Admin\SettingsController::class, 'site'])->name('settings');
        Route::post('/settings', [\App\Http\Controllers\Admin\SettingsController::class, 'saveSite'])->name('settings.save');

        // Settings — Hero
        Route::get('/hero', [\App\Http\Controllers\Admin\SettingsController::class, 'hero'])->name('hero');
        Route::post('/hero', [\App\Http\Controllers\Admin\SettingsController::class, 'saveHero'])->name('hero.save');

        // Settings — About
        Route::get('/about', [\App\Http\Controllers\Admin\SettingsController::class, 'about'])->name('about');
        Route::post('/about', [\App\Http\Controllers\Admin\SettingsController::class, 'saveAbout'])->name('about.save');

        // Settings — Process Steps
        Route::get('/process', [\App\Http\Controllers\Admin\SettingsController::class, 'process'])->name('process');
        Route::post('/process', [\App\Http\Controllers\Admin\SettingsController::class, 'saveProcess'])->name('process.save');

        // Settings — Why Us
        Route::get('/why-us', [\App\Http\Controllers\Admin\SettingsController::class, 'whyUs'])->name('why-us');
        Route::post('/why-us', [\App\Http\Controllers\Admin\SettingsController::class, 'saveWhyUs'])->name('why-us.save');

    }); // end admin middleware group
}); // end admin prefix
