<?php

use CodeIgniter\Router\RouteCollection;

/** @var RouteCollection $routes */

$routes->get('/', 'AuthController::entry');

// Public authentication (no session required).
$routes->group('', ['filter' => 'guest'], static function (RouteCollection $routes): void {
    $routes->get('sign-in', 'AuthController::index');
    $routes->post('auth/send-otp', 'AuthController::sendOtp');
    $routes->get('auth/verify-otp', 'AuthController::verifyForm');
    $routes->post('auth/verify-otp', 'AuthController::verifyOtp');
    $routes->post('auth/resend-otp', 'AuthController::resendOtp');
});

// Authenticated application. /logout is authenticated, not public.
$routes->group('', ['filter' => 'auth'], static function (RouteCollection $routes): void {
    $routes->get('logout', 'AuthController::logout');

    $routes->get('profile/onboarding', 'SettingsController::onboarding');
    $routes->post('profile/onboarding', 'SettingsController::completeOnboarding');

    $routes->get('dashboard', 'DashboardController::index');
    $routes->post('dashboard/filter', 'DashboardController::filter');

    $routes->get('tasks/search', 'TaskController::search');
    $routes->get('tasks/priority/(:num)', 'TaskController::byPriority/$1');
    $routes->get('tasks/create', 'TaskController::create');
    $routes->post('tasks/create', 'TaskController::store');
    $routes->get('tasks/(:num)/edit', 'TaskController::edit/$1');
    $routes->post('tasks/(:num)/edit', 'TaskController::update/$1');
    $routes->post('tasks/occurrences/(:num)/complete', 'TaskController::complete/$1');
    $routes->post('tasks/occurrences/(:num)/delete', 'TaskController::deleteOccurrence/$1');
    $routes->post('tasks/occurrences/(:num)/delete-future', 'TaskController::deleteThisAndFuture/$1');
    $routes->post('tasks/(:num)/delete', 'TaskController::deleteTask/$1');

    $routes->get('categories', 'CategoryController::index');
    $routes->post('categories', 'CategoryController::store');
    $routes->post('categories/(:num)', 'CategoryController::update/$1');
    $routes->post('categories/(:num)/delete', 'CategoryController::delete/$1');
    $routes->post('categories/(:num)/move-and-delete', 'CategoryController::moveAndDelete/$1');
    $routes->post('categories/(:num)/delete-with-tasks', 'CategoryController::deleteWithTasks/$1');

    $routes->get('analytics', 'AnalyticsController::index');

    $routes->get('notifications', 'NotificationController::index');
    $routes->post('notifications/read-all', 'NotificationController::markAllRead');
    $routes->post('notifications/(:num)/read', 'NotificationController::markRead/$1');
    $routes->post('notifications/(:num)/open', 'NotificationController::open/$1');

    $routes->get('support', 'SupportController::index');
    $routes->post('support', 'SupportController::submit');

    $routes->get('settings', 'SettingsController::index');
    $routes->post('settings/profile', 'SettingsController::updateProfile');
});
