<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

/**
 * RadiusBooking API Route Registrar
 *
 * This class is responsible for registering API routes dynamically with the WordPress REST API.
 * It supports CRUD operations and allows for middleware to be applied globally or per route.
 *
 * @package RadiusTheme\RadiusBooking\Core\Api\Routes
 */

use RadiusTheme\RadiusBooking\Controllers\AppointmentController;
use RadiusTheme\RadiusBooking\Controllers\CategoryController;
use RadiusTheme\RadiusBooking\Controllers\CustomerPanelController;
use RadiusTheme\RadiusBooking\Controllers\DashboardController;
use RadiusTheme\RadiusBooking\Controllers\EmailController;
use RadiusTheme\RadiusBooking\Controllers\EmployeePanelController;
use RadiusTheme\RadiusBooking\Controllers\PaymentController;
use RadiusTheme\RadiusBooking\Controllers\ServiceController;
use RadiusTheme\RadiusBooking\Controllers\SettingsController;
use RadiusTheme\RadiusBooking\Controllers\SetupWizardController;
use RadiusTheme\RadiusBooking\Controllers\UserController;
use RadiusTheme\RadiusBooking\Controllers\MeetingTypeController;
use RadiusTheme\RadiusBooking\Controllers\EventController;
use RadiusTheme\RadiusBooking\Controllers\EventRegistrationController;
use RadiusTheme\RadiusBooking\Controllers\EventTicketController;
use RadiusTheme\RadiusBooking\ExportImport\ExportImportController;

## Appointment Routes ##
$this->router->resource( 'appointments', AppointmentController::class );
$this->router->get( 'appointments/get-assign-services/(?P<service_id>\d+)', array( AppointmentController::class, 'getAssignServices' ) );
$this->router->get( 'appointments/get-employee-services', array( AppointmentController::class, 'getEmployeeServices' ) );
$this->router->get( 'appointments/employee-available-datetime/(?P<employee_id>\d+)', array( AppointmentController::class, 'getEmployeeAvailableDateTime' ) );
$this->router->get( 'appointments/employee-available-timeslot/(?P<employee_id>\d+)', array( AppointmentController::class, 'getEmployeeAvailableTimeslot' ) );
$this->router->put( 'appointments/(?P<id>\d+)/update-status', array( AppointmentController::class, 'updateStatus' ) );
$this->router->get( 'appointments/dashboard-data/', array( AppointmentController::class, 'getDashboardData' ) );
$this->router->get( 'appointments/calender-show', array( AppointmentController::class, 'calenderShow' ) );
$this->router->get( 'appointments/config', array( AppointmentController::class, 'getConfig' ) );
$this->router->delete( 'appointments/bulk-delete/', array( AppointmentController::class, 'bulkDelete' ) );
// Deposit / Update Payment Route.
$this->router->put( 'appointments/(?P<id>\d+)/update-payment/', array( AppointmentController::class, 'updatePayment' ) );

$this->router->post( 'appointments/paypal/create-order', array( AppointmentController::class, 'createPayPalOrder' ) );
$this->router->post( 'appointments/paypal/capture-order', array( AppointmentController::class, 'capturePayPalOrder' ) );

$this->router->resource( 'category', CategoryController::class );
$this->router->get( 'category/all', array( CategoryController::class, 'getAllCategory' ) );
$this->router->resource( 'users', UserController::class );

// User specific routes
$this->router->get( 'users/(?P<user_id>\d+)/profile', array( UserController::class, 'getProfile' ) );
$this->router->get( 'users/dashboard', array( UserController::class, 'getDashboard' ) );
$this->router->delete( 'users/bulk-delete/', array( UserController::class, 'bulkDelete' ) );
$this->router->put( 'users/(?P<user_id>\d+)/status', array( UserController::class, 'updateStatus' ) );
$this->router->get( 'get-employees', array( UserController::class, 'getEmployees' ) );

//phpcs:ignore
$this->router->resource( 'services', ServiceController::class );
$this->router->get( 'services/all', array( ServiceController::class, 'getAllServices' ) );
$this->router->delete( 'services/bulk-delete/', array( ServiceController::class, 'bulkDelete' ) );

## Payment Routes ##
$this->router->resource( 'payments', PaymentController::class );
$this->router->get( 'payments/dashboard', array( PaymentController::class, 'getDashboard' ) );
## Dashboard Routes ##
$this->router->get( 'dashboard/total-report', array( DashboardController::class, 'totalReport' ) );
$this->router->get( 'dashboard/today-report', array( DashboardController::class, 'todayReport' ) );
$this->router->get( 'dashboard/recent-activity', array( DashboardController::class, 'recentActivity' ) );
$this->router->get( 'dashboard/upcoming-appointment', array( DashboardController::class, 'upcomingAppointment' ) );
$this->router->get( 'dashboard/appointment-statistics', array( DashboardController::class, 'appointmentStatistics' ) );
$this->router->get( 'dashboard/revenue-statistics', array( DashboardController::class, 'revenueStatistics' ) );

## Settings Routes ##
$this->router->get( 'settings', array( SettingsController::class, 'index' ) );
$this->router->put( 'settings', array( SettingsController::class, 'update' ) );
$this->router->put( 'settings/reset', array( SettingsController::class, 'reset' ) );
$this->router->get( 'settings/(?P<section>[a-zA-Z0-9_-]+)', array( SettingsController::class, 'show' ) );//phpcs:ignore
$this->router->put( 'settings/(?P<section>[a-zA-Z0-9_-]+)', array( SettingsController::class, 'updateSection' ) );//phpcs:ignore

## Email Routes ##
$this->router->get( 'emails', array( EmailController::class, 'get_emails' ) );
$this->router->get( 'emails/(?P<email_id>[a-zA-Z0-9._%+-]+)', array( EmailController::class, 'get_email' ) );
$this->router->put( 'emails/(?P<email_id>[a-zA-Z0-9._%+-]+)', array( EmailController::class, 'update_email_settings' ) );

## Setup Wizard Routes ##
$this->router->get( 'setup-wizard/status', array( SetupWizardController::class, 'status' ) );
$this->router->post( 'setup-wizard/step/(?P<step>[a-zA-Z0-9_-]+)', array( SetupWizardController::class, 'saveStep' ) );
$this->router->post( 'setup-wizard/complete', array( SetupWizardController::class, 'complete' ) );
$this->router->post( 'setup-wizard/create-staff', array( SetupWizardController::class, 'createStaff' ) );

## Customer Panel Routes (free) ##
$this->router->get( 'customer/dashboard/(?P<user_id>\d+)', array( CustomerPanelController::class, 'customerDashboard' ) );
$this->router->get( 'customer/dashboard/profile/(?P<user_id>\d+)', array( CustomerPanelController::class, 'customerProfile' ) );
$this->router->put( 'customer/dashboard/profile/(?P<user_id>\d+)', array( CustomerPanelController::class, 'customerUpdateProfile' ) );
$this->router->post( 'customer/dashboard/profile/(?P<employee_id>\d+)/password', array( CustomerPanelController::class, 'customerChangePassword' ) );

## Employee Panel Routes (free) ##
$this->router->get( 'employee/dashboard/(?P<employee_id>\d+)', array( EmployeePanelController::class, 'employeeDashboard' ) );
$this->router->get( 'employee/dashboard/payment/(?P<employee_id>\d+)', array( EmployeePanelController::class, 'employeePayment' ) );
$this->router->get( 'employee/dashboard/customer/(?P<employee_id>\d+)', array( EmployeePanelController::class, 'employeeCustomer' ) );
$this->router->get( 'employee/dashboard/profile/(?P<employee_id>\d+)', array( EmployeePanelController::class, 'employeeProfile' ) );
$this->router->put( 'employee/dashboard/profile/(?P<employee_id>\d+)', array( EmployeePanelController::class, 'employeeUpdateProfile' ) );
$this->router->post( 'employee/dashboard/profile/(?P<employee_id>\d+)/password', array( EmployeePanelController::class, 'employeeChangePassword' ) );
$this->router->put( 'employee/dashboard/update-appointment-status/(?P<employee_id>\d+)/(?P<appointment_id>\d+)/(?P<status>\w+)', array( EmployeePanelController::class, 'updateAppointmentStatus' ) );
// Employee Schedule Route.
$this->router->get( 'employee/dashboard/schedule/(?P<employee_id>\d+)', array( EmployeePanelController::class, 'employeeSchedule' ) );

## Employee Service Management Routes ##
$this->router->get( 'employee/dashboard/(?P<employee_id>\d+)/services/(?P<service_id>\d+)', array( EmployeePanelController::class, 'getService' ) );
$this->router->put( 'employee/dashboard/(?P<employee_id>\d+)/services/(?P<service_id>\d+)', array( EmployeePanelController::class, 'updateService' ) );
$this->router->post( 'employee/dashboard/(?P<employee_id>\d+)/services', array( EmployeePanelController::class, 'createService' ) );
$this->router->delete( 'employee/dashboard/(?P<employee_id>\d+)/services/(?P<service_id>\d+)', array( EmployeePanelController::class, 'deleteService' ) );
$this->router->get( 'employee/dashboard/(?P<employee_id>\d+)/categories', array( EmployeePanelController::class, 'getCategories' ) );

## Employee Staff Management Routes (Pro) ##
$this->router->get( 'employee/dashboard/(?P<employee_id>\d+)/staff', array( EmployeePanelController::class, 'listStaff' ) );
$this->router->get( 'employee/dashboard/(?P<employee_id>\d+)/staff-settings', array( EmployeePanelController::class, 'getStaffSettings' ) );
$this->router->put( 'employee/dashboard/(?P<employee_id>\d+)/staff-settings', array( EmployeePanelController::class, 'updateStaffSettings' ) );
$this->router->get( 'employee/dashboard/(?P<employee_id>\d+)/staff/(?P<staff_id>\d+)', array( EmployeePanelController::class, 'getStaff' ) );
$this->router->post( 'employee/dashboard/(?P<employee_id>\d+)/staff', array( EmployeePanelController::class, 'createStaff' ) );
$this->router->put( 'employee/dashboard/(?P<employee_id>\d+)/staff/(?P<staff_id>\d+)', array( EmployeePanelController::class, 'updateStaff' ) );
$this->router->delete( 'employee/dashboard/(?P<employee_id>\d+)/staff/(?P<staff_id>\d+)', array( EmployeePanelController::class, 'deleteStaff' ) );
## Employee Schedule Management Routes ##
$this->router->get( 'employee/dashboard/(?P<employee_id>\d+)/schedule-settings', array( EmployeePanelController::class, 'getScheduleSettings' ) );
$this->router->put( 'employee/dashboard/(?P<employee_id>\d+)/weekdays', array( EmployeePanelController::class, 'updateWeekdays' ) );
$this->router->put( 'employee/dashboard/(?P<employee_id>\d+)/days-off', array( EmployeePanelController::class, 'updateDaysOff' ) );
$this->router->put( 'employee/dashboard/(?P<employee_id>\d+)/special-days', array( EmployeePanelController::class, 'updateSpecialDays' ) );

## Export/Import Routes ##
$this->router->get( 'export-import/modules', array( ExportImportController::class, 'getModules' ) );
$this->router->post( 'export-import/export/init', array( ExportImportController::class, 'initExport' ) );
$this->router->get( 'export-import/export/batch', array( ExportImportController::class, 'exportBatch' ) );
$this->router->post( 'export-import/import/init', array( ExportImportController::class, 'initImport' ) );
$this->router->post( 'export-import/import/batch', array( ExportImportController::class, 'importBatch' ) );
$this->router->post( 'export-import/import/cleanup', array( ExportImportController::class, 'cleanupImport' ) );

## Meeting Type Routes (admin — auth + module guard in controller) ##
$this->router->resource( 'meeting-types', MeetingTypeController::class );
$this->router->get( 'meeting-types/by-employee/(?P<employee_id>\d+)', array( MeetingTypeController::class, 'getByEmployee' ) );
$this->router->get( 'meeting-types/(?P<id>\d+)/available-slots', array( MeetingTypeController::class, 'getAvailableSlots' ) );

## Public Meeting Booking Routes (module guard in controller) ##
$this->router->get( 'public/meeting/(?P<slug>[a-zA-Z0-9_-]+)', array( MeetingTypeController::class, 'getPublicMeetingType' ) );
$this->router->get( 'public/meeting/(?P<slug>[a-zA-Z0-9_-]+)/slots', array( MeetingTypeController::class, 'getPublicAvailableSlots' ) );
$this->router->post( 'public/meeting/(?P<slug>[a-zA-Z0-9_-]+)/book', array( MeetingTypeController::class, 'bookMeeting' ) );

## Public Meeting Reschedule Routes (token-gated, no auth) ##
$this->router->get( 'public/meeting-bookings/(?P<token>[a-zA-Z0-9]+)', array( MeetingTypeController::class, 'getBookingByToken' ) );
$this->router->get( 'public/meeting-bookings/(?P<token>[a-zA-Z0-9]+)/slots', array( MeetingTypeController::class, 'getRescheduleSlots' ) );
$this->router->post( 'public/meeting-bookings/(?P<token>[a-zA-Z0-9]+)/reschedule', array( MeetingTypeController::class, 'rescheduleBooking' ) );

## Event Routes (admin — auth + module guard in controller) ##
$this->router->resource( 'events', EventController::class );
$this->router->put( 'events/(?P<id>\d+)/publish', array( EventController::class, 'publish' ) );
$this->router->get( 'events/(?P<id>\d+)/registrations', array( EventController::class, 'getRegistrations' ) );
$this->router->post( 'events/(?P<id>\d+)/check-in', array( EventController::class, 'checkIn' ) );

## Event Ticket Routes (admin) ##
$this->router->get( 'events/(?P<event_id>\d+)/tickets', array( EventTicketController::class, 'index' ) );
$this->router->post( 'events/(?P<event_id>\d+)/tickets', array( EventTicketController::class, 'store' ) );
$this->router->put( 'events/(?P<event_id>\d+)/tickets/(?P<id>\d+)', array( EventTicketController::class, 'update' ) );
$this->router->delete( 'events/(?P<event_id>\d+)/tickets/(?P<id>\d+)', array( EventTicketController::class, 'destroy' ) );

## Public Event Routes (module guard in controller) ##
$this->router->get( 'public/events', array( EventController::class, 'getPublicEventList' ) );
$this->router->get( 'public/events/(?P<slug>[a-zA-Z0-9_-]+)', array( EventController::class, 'getPublicEvent' ) );
$this->router->post( 'public/events/(?P<slug>[a-zA-Z0-9_-]+)/register', array( EventRegistrationController::class, 'register' ) );
$this->router->get( 'public/event-registration/(?P<registration_number>[a-zA-Z0-9]+)', array( EventRegistrationController::class, 'getByRegistrationNumber' ) );
$this->router->put( 'public/event-registration/(?P<id>\d+)/cancel', array( EventRegistrationController::class, 'cancel' ) );

## Pro Feature Routes — registered via pro plugin hooks ##
do_action( 'rtrb_register_pro_routes', $this->router );
