<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes->get('/', 'Home::index');

// API Routes
$routes->group('api', ['namespace' => 'App\Controllers\Api'], function ($routes) {
    // Handle preflight OPTIONS requests
    $routes->options('(:any)', static function() {
        return response();
    });

    // Auth routes
    $routes->post('auth/register', 'AuthController::register');
    $routes->post('auth/login', 'AuthController::login');
    $routes->get('auth/invitations/(:segment)', 'AuthController::invitation/$1');
    $routes->get('auth/public-update/(:segment)', 'AuthController::publicUpdateInvitation/$1');
    $routes->get('auth/profile', 'AuthController::profile');
    $routes->put('auth/profile', 'AuthController::updateProfile');
    $routes->post('auth/change-password', 'AuthController::changePassword');
    $routes->post('auth/sms-token/request', 'AuthController::requestSmsToken');
    $routes->post('auth/sms-token/verify', 'AuthController::verifySmsToken');

    // Members routes
    $routes->get('members', 'MembersController::index');
    $routes->post('members', 'MembersController::create');
    $routes->post('members/invite', 'MembersController::invite');
    $routes->post('members/(:num)/public-link', 'MembersController::generatePublicLink/$1');
    $routes->get('members/me', 'MembersController::me');
    $routes->get('members/(:num)', 'MembersController::show/$1');
    $routes->put('members/(:num)', 'MembersController::update/$1');
    $routes->delete('members/(:num)', 'MembersController::delete/$1');
    $routes->get('members/search', 'MembersController::search');
    $routes->get('members/statuses', 'MembersController::getStatuses');
    $routes->get('members/stats', 'MembersController::getStats');

    // Beneficiaries routes
    $routes->get('beneficiaries/member/(:num)', 'BeneficiariesController::getByMember/$1');
    $routes->post('beneficiaries', 'BeneficiariesController::create');
    $routes->get('beneficiaries/public/(:segment)', 'BeneficiariesController::publicByToken/$1');
    $routes->post('beneficiaries/public', 'BeneficiariesController::publicCreate');
    $routes->put('beneficiaries/public/(:num)', 'BeneficiariesController::publicUpdate/$1');
    $routes->post('beneficiaries/public/validate', 'BeneficiariesController::publicValidate');
    $routes->get('beneficiaries/(:num)', 'BeneficiariesController::show/$1');
    $routes->put('beneficiaries/(:num)', 'BeneficiariesController::update/$1');
    $routes->delete('beneficiaries/(:num)', 'BeneficiariesController::delete/$1');
    $routes->post('beneficiaries/validate/(:num)', 'BeneficiariesController::validateDistribution/$1');

    // Payments routes
    $routes->get('payments', 'PaymentsController::index');
    $routes->get('payments/member/(:num)', 'PaymentsController::getByMember/$1');
    $routes->post('payments', 'PaymentsController::create');
    $routes->get('payments/(:num)', 'PaymentsController::show/$1');
    $routes->post('payments/qr/(:num)', 'PaymentsController::generateQRCode/$1');
    $routes->post('payments/mark-paid/(:num)', 'PaymentsController::markAsPaid/$1');
    $routes->get('payments/outstanding', 'PaymentsController::getOutstanding');
    $routes->get('payments/stats', 'PaymentsController::getStats');

    // Payment Transactions routes
    $routes->get('payment-trans', 'PaymentTransController::index');
    $routes->get('payment-trans/member/(:num)', 'PaymentTransController::getByMember/$1');
    $routes->post('payment-trans', 'PaymentTransController::create');
    $routes->get('payment-trans/(:num)', 'PaymentTransController::show/$1');
    $routes->put('payment-trans/(:num)', 'PaymentTransController::update/$1');
    $routes->delete('payment-trans/(:num)', 'PaymentTransController::delete/$1');
    $routes->get('payment-trans/unmatched', 'PaymentTransController::getUnmatched');
    $routes->post('payment-trans/match/(:num)', 'PaymentTransController::match/$1');
    $routes->post('payment-trans/match/(:num)/(:num)', 'PaymentTransController::match/$1/$2');
    $routes->post('payment-trans/unmatch/(:num)', 'PaymentTransController::unmatch/$1');
    $routes->get('payment-trans/matching', 'PaymentTransController::getMatching');
    $routes->get('payment-trans/stats', 'PaymentTransController::getStats');

    // Claims routes
    $routes->get('claims', 'ClaimsController::index');
    $routes->get('claims/member/(:num)', 'ClaimsController::getByMember/$1');
    $routes->post('claims', 'ClaimsController::create');
    $routes->get('claims/(:num)', 'ClaimsController::show/$1');
    $routes->post('claims/approve/(:num)', 'ClaimsController::approve/$1');
    $routes->post('claims/reject/(:num)', 'ClaimsController::reject/$1');
    $routes->post('claims/mark-paid/(:num)', 'ClaimsController::markAsPaid/$1');
    $routes->get('claims/stats', 'ClaimsController::getStats');
});
