<?php

use App\Core\Router;

// Public home page
Router::get('/', ['HomeController', 'index']);

// Auth routes
Router::get('/login', ['AuthController', 'showLogin']);
Router::post('/login', ['AuthController', 'login']);
Router::get('/logout', ['AuthController', 'logout']);
Router::get('/register', ['AuthController', 'showRegister']);
Router::post('/register', ['AuthController', 'register']);
Router::get('/forgot-password', ['AuthController', 'showForgotPassword']);
Router::post('/forgot-password', ['AuthController', 'forgotPassword']);
Router::get('/reset-password', ['AuthController', 'showResetPassword']);
Router::post('/reset-password', ['AuthController', 'resetPassword']);

// Dashboard
Router::get('/dashboard', ['DashboardController', 'index']);

// Users CRUD
Router::get('/users', ['UserController', 'index']);
Router::get('/users/pending', ['UserController', 'pending']);
Router::get('/users/{id}/review', ['UserController', 'review']);
Router::post('/users/{id}/approve', ['UserController', 'approve']);
Router::post('/users/{id}/reject', ['UserController', 'reject']);
Router::get('/users/create', ['UserController', 'create']);
Router::post('/users/store', ['UserController', 'store']);
Router::get('/users/{id}/edit', ['UserController', 'edit']);
Router::post('/users/{id}/update', ['UserController', 'update']);
Router::post('/users/{id}/delete', ['UserController', 'delete']);

// Profile
Router::get('/profile', ['UserController', 'profile']);
Router::post('/profile/update', ['UserController', 'updateProfile']);
Router::post('/profile/avatar', ['UserController', 'updateAvatar']);

// Settings
Router::get('/settings', ['SettingsController', 'index']);
Router::post('/settings/update', ['SettingsController', 'update']);
Router::post('/settings/test-email', ['SettingsController', 'testEmail']);
Router::get('/settings/backup', ['SettingsController', 'backup']);
Router::post('/settings/restore', ['SettingsController', 'restore']);

// CMS
Router::get('/cms', ['CmsController', 'index']);
Router::get('/cms/{slug}/edit', ['CmsController', 'edit']);
Router::post('/cms/{slug}/update', ['CmsController', 'update']);

// Post Categories (Admin)
Router::get('/post-categories', ['PostCategoryController', 'index']);
Router::get('/post-categories/create', ['PostCategoryController', 'create']);
Router::post('/post-categories/store', ['PostCategoryController', 'store']);
Router::get('/post-categories/{id}/edit', ['PostCategoryController', 'edit']);
Router::post('/post-categories/{id}/update', ['PostCategoryController', 'update']);
Router::post('/post-categories/{id}/delete', ['PostCategoryController', 'delete']);

// Audit
Router::get('/audit', ['AuditController', 'index']);

// Static pages
Router::get('/charts', ['DashboardController', 'charts']);
Router::get('/tables', ['DashboardController', 'tables']);

// Calendar
Router::get('/calendar', ['CalendarController', 'index']);
Router::post('/calendar/store', ['CalendarController', 'store']);
Router::post('/calendar/{id}/update', ['CalendarController', 'updateEvent']);
Router::post('/calendar/{id}/delete', ['CalendarController', 'destroy']);

// ============================================================
// MEMBERSHIP MODULES
// ============================================================

// Member Dashboard & Profile
Router::get('/member/dashboard', ['MemberController', 'dashboard']);
Router::get('/member/profile', ['MemberController', 'profile']);
Router::post('/member/profile/save', ['MemberController', 'saveProfile']);
Router::post('/member/profile/avatar', ['MemberController', 'updateAvatar']);
Router::get('/members', ['MemberController', 'members']);
Router::get('/members/{id}', ['MemberController', 'detail']);
Router::post('/members/{id}/toggle-status', ['MemberController', 'toggleStatus']);
Router::post('/members/{id}/assign-type', ['MemberController', 'assignContributionType']);
Router::post('/members/{id}/unassign-type/{typeId}', ['MemberController', 'unassignContributionType']);
Router::post('/members/{id}/message', ['MemberController', 'quickMessage']);

// Announcements
Router::get('/announcements', ['AnnouncementController', 'index']);
Router::get('/announcements/create', ['AnnouncementController', 'create']);
Router::post('/announcements/store', ['AnnouncementController', 'store']);
Router::get('/announcements/{id}/edit', ['AnnouncementController', 'edit']);
Router::post('/announcements/{id}/update', ['AnnouncementController', 'update']);
Router::post('/announcements/{id}/delete', ['AnnouncementController', 'delete']);

// Events
Router::get('/events', ['EventController', 'index']);
Router::get('/events/create', ['EventController', 'create']);
Router::post('/events/store', ['EventController', 'store']);
Router::get('/events/{id}', ['EventController', 'show']);
Router::get('/events/{id}/edit', ['EventController', 'edit']);
Router::post('/events/{id}/update', ['EventController', 'update']);
Router::post('/events/{id}/delete', ['EventController', 'delete']);
Router::post('/events/{id}/register', ['EventController', 'register']);
Router::post('/events/{id}/unregister', ['EventController', 'unregister']);
Router::get('/events/{id}/attendees', ['EventController', 'attendees']);

// Messages
Router::get('/messages/inbox', ['MessageController', 'inbox']);
Router::get('/messages/sent', ['MessageController', 'sent']);
Router::get('/messages/compose', ['MessageController', 'compose']);
Router::get('/messages/search-users', ['MessageController', 'searchUsers']);
Router::post('/messages/send', ['MessageController', 'send']);
Router::get('/messages/{id}', ['MessageController', 'show']);
Router::post('/messages/{id}/delete', ['MessageController', 'delete']);

// Forum
Router::get('/forum', ['ForumController', 'index']);
Router::get('/forum/category/{id}', ['ForumController', 'category']);
Router::get('/forum/topic/{id}', ['ForumController', 'topic']);
Router::get('/forum/{id}/create-topic', ['ForumController', 'createTopic']);
Router::post('/forum/store-topic', ['ForumController', 'storeTopic']);
Router::post('/forum/topic/{id}/reply', ['ForumController', 'reply']);
Router::post('/forum/post/{id}/delete', ['ForumController', 'deletePost']);
Router::post('/forum/topic/{id}/delete', ['ForumController', 'deleteTopic']);
Router::post('/forum/topic/{id}/pin', ['ForumController', 'togglePin']);
Router::post('/forum/topic/{id}/lock', ['ForumController', 'toggleLock']);

// Documents
Router::get('/documents', ['DocumentController', 'index']);
Router::get('/documents/category/{id}', ['DocumentController', 'category']);
Router::get('/documents/upload', ['DocumentController', 'upload']);
Router::post('/documents/store', ['DocumentController', 'store']);
Router::get('/documents/{id}/download', ['DocumentController', 'download']);
Router::post('/documents/{id}/delete', ['DocumentController', 'delete']);

// Photos
Router::get('/photos', ['PhotoController', 'albums']);
Router::get('/photos/album/{id}', ['PhotoController', 'album']);
Router::get('/photos/create-album', ['PhotoController', 'createAlbum']);
Router::post('/photos/store-album', ['PhotoController', 'storeAlbum']);
Router::post('/photos/album/{id}/upload', ['PhotoController', 'upload']);
Router::post('/photos/album/{id}/delete', ['PhotoController', 'deleteAlbum']);
Router::post('/photos/{id}/delete', ['PhotoController', 'deletePhoto']);

// Custom Links
Router::get('/links', ['LinkController', 'index']);
Router::get('/links/create', ['LinkController', 'create']);
Router::post('/links/store', ['LinkController', 'store']);
Router::get('/links/{id}/edit', ['LinkController', 'edit']);
Router::post('/links/{id}/update', ['LinkController', 'update']);
Router::post('/links/{id}/delete', ['LinkController', 'delete']);

// Contributions
Router::get('/contributions', ['ContributionController', 'index']);
Router::get('/contributions/create', ['ContributionController', 'create']);
Router::post('/contributions/store', ['ContributionController', 'store']);
Router::get('/contributions/member', ['ContributionController', 'member']);
Router::get('/contributions/{id}/edit', ['ContributionController', 'edit']);
Router::post('/contributions/{id}/update', ['ContributionController', 'update']);
Router::post('/contributions/{id}/approve', ['ContributionController', 'approve']);
Router::get('/contributions/receipt/{id}/download', ['ContributionController', 'downloadReceipt']);
Router::get('/contributions/add-payment', ['ContributionController', 'addPayment']);
Router::get('/contributions/search-members', ['ContributionController', 'searchMembers']);
Router::get('/contributions/arrears', ['ContributionController', 'arrears']);
Router::get('/receipts', ['ContributionController', 'receipts']);

// Contribution Types (Admin)
Router::get('/contribution-types', ['ContributionTypeController', 'index']);
Router::get('/contribution-types/create', ['ContributionTypeController', 'create']);
Router::post('/contribution-types/store', ['ContributionTypeController', 'store']);
Router::get('/contribution-types/{id}/edit', ['ContributionTypeController', 'edit']);
Router::post('/contribution-types/{id}/update', ['ContributionTypeController', 'update']);
Router::post('/contribution-types/{id}/delete', ['ContributionTypeController', 'delete']);
Router::get('/contribution-types/{id}/members', ['ContributionTypeController', 'members']);
Router::post('/contribution-types/{id}/assign-member', ['ContributionTypeController', 'assignMember']);
Router::post('/contribution-types/{id}/unassign-member', ['ContributionTypeController', 'unassignMember']);
Router::post('/contribution-types/{id}/bulk-assign', ['ContributionTypeController', 'bulkAssign']);

// Attendance
Router::get('/attendance', ['AttendanceController', 'index']);
Router::post('/attendance/{id}/mark', ['AttendanceController', 'markAttendance']);

// Birthdays
Router::get('/birthdays', ['BirthdayController', 'index']);
Router::get('/birthdays/wishes/{id}', ['BirthdayController', 'wishes']);
Router::post('/birthdays/wishes/{id}/send', ['BirthdayController', 'sendWish']);

// Reports
Router::get('/reports/members', ['ReportController', 'members']);
Router::get('/reports/members/{id}', ['ReportController', 'member']);

// Profile Fields (Admin)
Router::get('/profile-fields', ['ProfileFieldController', 'index']);
Router::get('/profile-fields/create', ['ProfileFieldController', 'create']);
Router::post('/profile-fields/store', ['ProfileFieldController', 'store']);
Router::get('/profile-fields/{id}/edit', ['ProfileFieldController', 'edit']);
Router::post('/profile-fields/{id}/update', ['ProfileFieldController', 'update']);
Router::post('/profile-fields/{id}/delete', ['ProfileFieldController', 'delete']);
Router::post('/profile-fields/reorder', ['ProfileFieldController', 'reorder']);

// Dynamic Forms
Router::get('/forms', ['DynamicFormController', 'index']);
Router::get('/forms/create', ['DynamicFormController', 'create']);
Router::post('/forms/store', ['DynamicFormController', 'store']);
// Field Templates (must be before {id} wildcard)
Router::get('/forms/field-templates', ['DynamicFormController', 'fieldTemplates']);
Router::post('/forms/field-templates/store', ['DynamicFormController', 'storeFieldTemplate']);
Router::post('/forms/field-templates/{id}/delete', ['DynamicFormController', 'deleteFieldTemplate']);
// Shared form access (must be before {id} wildcard)
Router::get('/forms/shared/{token}', ['DynamicFormController', 'accessShared']);
Router::post('/forms/shared/{token}/submit', ['DynamicFormController', 'submitShared']);
Router::get('/forms/shared/{token}/thank-you', ['DynamicFormController', 'thankYouShared']);
// {id} routes
Router::get('/forms/{id}', ['DynamicFormController', 'show']);
Router::post('/forms/{id}/submit', ['DynamicFormController', 'submit']);
Router::get('/forms/{id}/submissions', ['DynamicFormController', 'submissions']);
Router::get('/forms/{id}/edit', ['DynamicFormController', 'edit']);
Router::post('/forms/{id}/update', ['DynamicFormController', 'update']);
Router::post('/forms/{id}/delete', ['DynamicFormController', 'delete']);
Router::get('/forms/{id}/thank-you', ['DynamicFormController', 'thankYou']);
Router::post('/forms/{id}/duplicate', ['DynamicFormController', 'duplicate']);
Router::post('/forms/{id}/save-template', ['DynamicFormController', 'saveAsTemplate']);
Router::post('/forms/{id}/delete-template', ['DynamicFormController', 'deleteTemplate']);
Router::get('/forms/{id}/share', ['DynamicFormController', 'share']);
Router::post('/forms/{id}/share/generate', ['DynamicFormController', 'generateShareLink']);
Router::post('/forms/{id}/share/{token}/send', ['DynamicFormController', 'sendShare']);
Router::post('/forms/share/{shareId}/revoke', ['DynamicFormController', 'revokeShare']);

// Payment Gateway
Router::get('/payment/make', ['PaymentController', 'make']);
Router::post('/payment/init', ['PaymentController', 'init']);
Router::get('/payment/callback', ['PublicPaymentController', 'callback']);
Router::post('/payment/webhook/{gateway}', ['PublicPaymentController', 'webhook']);
Router::get('/payments/requests', ['PaymentRequestController', 'index']);
Router::post('/payments/requests/{id}/resend', ['PaymentRequestController', 'resend']);

// Loans
Router::get('/loans', ['LoanController', 'index']);
Router::get('/loans/apply', ['LoanController', 'apply']);
Router::post('/loans/store', ['LoanController', 'store']);
Router::get('/loans/my', ['LoanController', 'my']);
Router::get('/loans/types', ['LoanController', 'types']);
Router::get('/loans/types/create', ['LoanController', 'createType']);
Router::post('/loans/types/store', ['LoanController', 'storeType']);
Router::get('/loans/types/{id}/edit', ['LoanController', 'editType']);
Router::post('/loans/types/{id}/update', ['LoanController', 'updateType']);
Router::post('/loans/types/{id}/delete', ['LoanController', 'deleteType']);
Router::get('/loans/{id}', ['LoanController', 'detail']);
Router::post('/loans/{id}/approve', ['LoanController', 'approve']);
Router::post('/loans/{id}/reject', ['LoanController', 'reject']);
Router::post('/loans/{id}/disburse', ['LoanController', 'disburse']);
Router::post('/loans/{id}/complete', ['LoanController', 'markCompleted']);
Router::post('/loans/{id}/default', ['LoanController', 'markDefaulted']);
Router::post('/loans/repayments/{id}/pay', ['LoanController', 'recordRepayment']);

// Cron route for loan deductions and reminders
Router::get('/cron/loan-deductions', ['LoanController', 'processDeductions']);
// Cron route for profile reminders
Router::get('/cron/profile-reminder', ['UserController', 'reminderCron']);

// Cron route for payment reminders
Router::get('/cron/payment-reminder', ['ContributionController', 'reminderCron']);
