<?php
declare(strict_types=1);

namespace App;

use App\Middleware\RequireRole;
use App\Middleware\RequirePin;

class Routes
{
    public static function register(Router $router): void
    {
        // ------------ Public site ------------
        $router->get('/',                ['App\Controllers\PublicController', 'home']);
        $router->get('/about',           ['App\Controllers\PublicController', 'about']);
        $router->get('/artists',         ['App\Controllers\PublicController', 'artists']);
        $router->get('/artists/{slug}',  ['App\Controllers\PublicController', 'artistDetail']);
        $router->get('/portfolio',       ['App\Controllers\PublicController', 'portfolio']);
        $router->get('/aftercare',       ['App\Controllers\PublicController', 'aftercare']);
        $router->get('/contact',         ['App\Controllers\PublicController', 'contact']);
        $router->post('/contact',        ['App\Controllers\PublicController', 'contactSubmit']);
        $router->get('/faq',             ['App\Controllers\PublicController', 'faq']);

        // Locale toggle
        $router->get('/lang/{code}',     ['App\Controllers\PublicController', 'setLang']);

        // ------------ Booking wizard ------------
        $router->get('/book',                ['App\Controllers\BookingController', 'start']);
        $router->get('/book/step/{n}',       ['App\Controllers\BookingController', 'step']);
        $router->post('/book/step/{n}',      ['App\Controllers\BookingController', 'saveStep']);
        $router->get('/book/review',         ['App\Controllers\BookingController', 'review']);
        $router->post('/book/submit',        ['App\Controllers\BookingController', 'submit']);
        $router->get('/book/confirm/{id}',   ['App\Controllers\BookingController', 'confirm']);
        $router->get('/book/resume',         ['App\Controllers\BookingController', 'resume']);

        // ------------ Public intake form (customer fills online before visit) ------------
        $router->get('/intake/{token}',      ['App\Controllers\CustomerIntakeController', 'show']);
        $router->post('/intake/{token}',     ['App\Controllers\CustomerIntakeController', 'save']);

        // ------------ Public reschedule (customer approves/rejects via email link) ------------
        $router->get('/reschedule/{token}/approve', ['App\Controllers\RescheduleController', 'approve']);
        $router->get('/reschedule/{token}/reject',  ['App\Controllers\RescheduleController', 'reject']);

        // ------------ Public API ------------
        $router->get('/api/availability',    ['App\Controllers\ApiController', 'availability']);
        $router->post('/api/booking/draft',  ['App\Controllers\ApiController', 'saveDraft']);
        $router->post('/api/uploads/reference', ['App\Controllers\ApiController', 'uploadReference']);

        // ------------ Shop Hub ------------
        $router->get('/hub/login',         ['App\Controllers\HubController', 'loginForm']);
        $router->post('/hub/login',        ['App\Controllers\HubController', 'login']);
        $router->get('/hub/logout',        ['App\Controllers\HubController', 'logout']);

        $staff = [new RequireRole(['STAFF', 'ADMIN', 'ARTIST'])];
        $router->get('/hub',                       ['App\Controllers\HubController', 'dashboard'], $staff);
        $router->get('/hub/change-password',       ['App\Controllers\HubController', 'changePasswordForm'], $staff);
        $router->post('/hub/change-password',      ['App\Controllers\HubController', 'changePassword'], $staff);
        $router->get('/hub/setup-pin',             ['App\Controllers\HubController', 'setupPinForm'], $staff);
        $router->post('/hub/setup-pin',            ['App\Controllers\HubController', 'setupPin'], $staff);

        $router->get('/hub/appointments',          ['App\Controllers\HubAppointmentsController', 'index'], $staff);
        $router->get('/hub/appointments/{id}',     ['App\Controllers\HubAppointmentsController', 'show'], $staff);
        $router->post('/hub/appointments/{id}/approve', ['App\Controllers\HubAppointmentsController', 'approve'], $staff);
        $router->post('/hub/appointments/{id}/cancel',  ['App\Controllers\HubAppointmentsController', 'cancel'], $staff);
        $router->post('/hub/appointments/{id}/complete',['App\Controllers\HubAppointmentsController', 'complete'], $staff);
        $router->post('/hub/appointments/{id}/notes',      ['App\Controllers\HubAppointmentsController', 'saveNotes'], $staff);
        $router->post('/hub/appointments/{id}/reschedule', ['App\Controllers\HubAppointmentsController', 'reschedule'], $staff);

        $router->get('/hub/customers',             ['App\Controllers\HubCustomersController', 'index'], $staff);
        $router->get('/hub/customers/search',      ['App\Controllers\HubCustomersController', 'search'], $staff);
        $router->get('/hub/customers/{id}',        ['App\Controllers\HubCustomersController', 'show'], $staff);

        $router->get('/hub/forms',                 ['App\Controllers\HubFormsController', 'index'], $staff);
        $router->get('/hub/forms/new',             ['App\Controllers\HubFormsController', 'create'], $staff);
        $router->get('/hub/forms/{id}',            ['App\Controllers\HubFormsController', 'show'], $staff);
        $router->post('/hub/forms/{id}/save',      ['App\Controllers\HubFormsController', 'save'], $staff);
        $router->post('/hub/forms/{id}/sign',      ['App\Controllers\HubFormsController', 'sign'], $staff);

        $router->get('/hub/walkin',                ['App\Controllers\HubWalkinController', 'start'], $staff);
        $router->post('/hub/walkin/lookup',        ['App\Controllers\HubWalkinController', 'lookup'], $staff);
        $router->post('/hub/walkin/create',        ['App\Controllers\HubWalkinController', 'create'], $staff);

        $router->get('/hub/new-appointment',              ['App\Controllers\HubNewAppointmentController', 'start'], $staff);
        $router->post('/hub/new-appointment/lookup',      ['App\Controllers\HubNewAppointmentController', 'lookup'], $staff);
        $router->post('/hub/new-appointment/create',      ['App\Controllers\HubNewAppointmentController', 'create'], $staff);

        $router->get('/hub/account',               ['App\Controllers\HubAccountController', 'show'], $staff);
        $router->post('/hub/account/password',     ['App\Controllers\HubAccountController', 'changePassword'], $staff);
        $router->post('/hub/account/pin',          ['App\Controllers\HubAccountController', 'changePin'], $staff);
        $router->get('/hub/account/schedule',      ['App\Controllers\HubAccountController', 'schedule'], $staff);
        $router->post('/hub/account/schedule',     ['App\Controllers\HubAccountController', 'saveSchedule'], $staff);
        $router->post('/hub/customers/{id}/delete',['App\Controllers\HubCustomersController', 'delete'], $staff);

        // ------------ Admin ------------
        $admin = [new RequireRole(['ADMIN'])];
        $router->get('/admin',               ['App\Controllers\AdminController', 'overview'], $admin);
        $router->get('/admin/users',         ['App\Controllers\AdminController', 'users'], $admin);
        $router->get('/admin/users/{id}',    ['App\Controllers\AdminController', 'userDetail'], $admin);

        $router->get('/admin/staff',         ['App\Controllers\AdminStaffController', 'index'], $admin);
        $router->post('/admin/staff',        ['App\Controllers\AdminStaffController', 'create'], $admin);
        $router->post('/admin/staff/{id}/reset-pin',      ['App\Controllers\AdminStaffController', 'resetPin'], $admin);
        $router->post('/admin/staff/{id}/reset-password', ['App\Controllers\AdminStaffController', 'resetPassword'], $admin);
        $router->post('/admin/staff/{id}/disable',        ['App\Controllers\AdminStaffController', 'disable'], $admin);
        $router->post('/admin/staff/{id}/enable',         ['App\Controllers\AdminStaffController', 'enable'], $admin);

        $router->get('/admin/artists',          ['App\Controllers\AdminArtistsController', 'index'], $admin);
        $router->post('/admin/artists',         ['App\Controllers\AdminArtistsController', 'create'], $admin);
        $router->get('/admin/artists/{id}',     ['App\Controllers\AdminArtistsController', 'edit'], $admin);
        $router->post('/admin/artists/{id}',    ['App\Controllers\AdminArtistsController', 'update'], $admin);
        $router->post('/admin/artists/{id}/delete', ['App\Controllers\AdminArtistsController', 'delete'], $admin);

        $router->get('/admin/artists/{id}/schedule', ['App\Controllers\AdminScheduleController', 'edit'], $admin);
        $router->post('/admin/artists/{id}/schedule',['App\Controllers\AdminScheduleController', 'update'], $admin);

        $router->get('/admin/gallery',          ['App\Controllers\AdminController', 'gallery'], $admin);
        $router->post('/admin/gallery',         ['App\Controllers\AdminController', 'galleryAdd'], $admin);
        $router->post('/admin/gallery/{id}/delete', ['App\Controllers\AdminController', 'galleryDelete'], $admin);

        $router->get('/admin/audit',            ['App\Controllers\AdminController', 'audit'], $admin);
        $router->get('/admin/settings',         ['App\Controllers\AdminController', 'settings'], $admin);
        $router->post('/admin/settings',        ['App\Controllers\AdminController', 'saveSettings'], $admin);

        $router->post('/admin/test-email',      ['App\Controllers\AdminController', 'testEmail'], $admin);
        $router->get('/admin/export',           ['App\Controllers\AdminController', 'exportData'], $admin);
        $router->post('/admin/clear-data',      ['App\Controllers\AdminController', 'clearData'], $admin);
        $router->post('/admin/import-data',     ['App\Controllers\AdminController', 'importData'], $admin);
    }
}
