<?php

/**
 * Messaging routes.
 * @var \CodeIgniter\Router\RouteCollection $routes
 */

$routes->group('messages', ['filter' => 'auth'], static function ($routes) {
    $routes->get('/', '\Modules\Messaging\Controllers\MessageController::index', ['filter' => 'permission:messages.view']);
    $routes->post('direct', '\Modules\Messaging\Controllers\MessageController::startDirect', ['filter' => 'permission:messages.send']);

    // Groups (admin) — register before (:num) routes
    $routes->get('groups', '\Modules\Messaging\Controllers\GroupController::index', ['filter' => 'permission:messages.manage_groups']);
    $routes->get('groups/create', '\Modules\Messaging\Controllers\GroupController::createForm', ['filter' => 'permission:messages.manage_groups']);
    $routes->post('groups', '\Modules\Messaging\Controllers\GroupController::store', ['filter' => 'permission:messages.manage_groups']);
    $routes->get('groups/(:num)/edit', '\Modules\Messaging\Controllers\GroupController::editForm/$1', ['filter' => 'permission:messages.manage_groups']);
    $routes->post('groups/(:num)', '\Modules\Messaging\Controllers\GroupController::update/$1', ['filter' => 'permission:messages.manage_groups']);
    $routes->post('groups/(:num)/delete', '\Modules\Messaging\Controllers\GroupController::destroy/$1', ['filter' => 'permission:messages.manage_groups']);

    $routes->post('(:num)/send', '\Modules\Messaging\Controllers\MessageController::send/$1', ['filter' => 'permission:messages.send']);
    $routes->get('(:num)/poll', '\Modules\Messaging\Controllers\MessageController::poll/$1', ['filter' => 'permission:messages.view']);
});
