<?php

use CodeIgniter\Router\RouteCollection;

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

   // PUBLIC
    $routes->post('login', 'API\AuthController::login');

    // 🔐 AUTH REQUIRED
    $routes->group('', ['filter' => 'auth'], function($routes) {

        $routes->get('profile', 'API\AuthController::profile');
        $routes->get('dashboard', 'Api\Dashboard::index');

        // =========================
        // 👑 ADMIN ONLY
        // =========================
        $routes->group('', ['filter' => 'role:admin'], function($routes) {
            $routes->get('reports', 'API\ReportController::index');

        });

        // =========================
        // 💼 ADMIN + KASIR
        // =========================
        $routes->group('', ['filter' => 'role:admin,kasir'], function($routes) {
        // ORDER
            $routes->get('orders', 'API\OrderController::index');
            $routes->get('orders/(:num)', 'API\OrderController::show/$1');
            $routes->post('orders', 'API\OrderController::create');
            $routes->post('orders/status/(:num)', 'API\OrderController::updateStatus/$1');
        });

        // =========================
        // 🚚 KURIR
        // =========================
        $routes->group('', ['filter' => 'role:kurir'], function($routes) {
            $routes->get('pickup', 'API\PickupController::index');
        });

        // CUSTOMERS
$routes->get('customers', 'API\CustomerController::index');
$routes->post('customers', 'API\CustomerController::create');
$routes->post('customers/(:num)', 'API\CustomerController::update/$1');
$routes->delete('customers/(:num)', 'API\CustomerController::delete/$1');
$routes->get('customers/deleted', 'API\CustomerController::deleted');
$routes->post('customers/restore/(:num)', 'API\CustomerController::restore/$1');
    });


// SERVICES
    $routes->get('services', 'API\ServiceController::index');
    $routes->post('services', 'API\ServiceController::create');
    $routes->put('services/(:num)', 'API\ServiceController::update/$1');
    $routes->delete('services/(:num)', 'API\ServiceController::delete/$1');
// PAYMENTS
$routes->post('payments', 'API\PaymentController::create');
   // USERS
    $routes->get('users', 'API\UserController::index');
    $routes->post('users', 'API\UserController::create');
    $routes->put('users/(:num)', 'API\UserController::update/$1');
    $routes->delete('users/(:num)', 'API\UserController::delete/$1');

    $routes->post('users/change-password/(:num)', 'API\UserController::changePassword/$1');

});