<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */

/*
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 */

// $routes->setDefaultNamespace('App\Controllers');
// $routes->setDefaultController('Dashboard');
// $routes->setDefaultMethod('index');
// $routes->setTranslateURIDashes(false);
// $routes->set404Override();

// The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps
// where controller filters or CSRF protection are bypassed.
// If you don't want to define all routes, please use the Auto Routing (Improved).
// Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true.
// $routes->setAutoRoute(false);

/*
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->match(['get','post'], '/auth/login', 'Auth::login');
$routes->match(['get','post'], '/auth/setPass', 'Auth::setPass');
$routes->get( '/auth/logout', 'Auth::logout');

//$routes->get('/', 'Home::index',['filter'=>'auth']);
$routes->get('/', 'Dashboard::index/0' );
$routes->get('/Dashboard', 'Dashboard::index/0');
$routes->get('/Dashboard/user/(:num)', 'Dashboard::index/$1');
//zones
$routes->get('/zones', 'Zones::index');
$routes->match(['get','post'],'/zones/edit/(:num)', 'Zones::edit/$1');
$routes->match(['get','post'],'/zones/create', 'Zones::edit/0');
//areas
$routes->get('/areas','Areas::index');
$routes->match(['get','post'],'/areas/edit/(:num)', 'Areas::edit/$1');
$routes->match(['get','post'],'/areas/create', 'Areas::edit/0');
$routes->match(['get','post'],'/areazone/edit/(:num)', 'Areas::areazone_edit/$1');
$routes->match(['get','post'],'/areazone/newrow', 'Areas::areazone_newrow');
// accounts
$routes->match(['get','post'],'/accounts', 'Accounts::index');
$routes->get('/accounts/view/(:num)', 'Accounts::view/$1');
$routes->match(['get','post'],'/accounts/edit/(:num)', 'Accounts::edit/$1');
$routes->match(['get','post'],'/accounts/create', 'Accounts::edit/0');
$routes->get('/accounts/toggle/(:num)', 'Accounts::toggle/$1');
$routes->get('/accounts/getcity/(:num)', 'Accounts::getcity/$1');
// sites
$routes->match(['get', 'post'],'/sites', 'Sites::index');
$routes->get('/sites/view/(:num)', 'Sites::view/$1');
$routes->match(['get', 'post'], '/sites/edit/(:any)', 'Sites::edit/$1');
$routes->match(['get', 'post'], '/sites/create', 'Sites::edit/0');
$routes->get('/sites/toggle/(:num)', 'Sites::toggle/$1');
$routes->get('/sites/log/delete/(:num)', 'Sites::siteslog_delete/$1');
$routes->match(['get', 'post'],'/sites/log/edit/(:num)', 'Sites::siteslog_edit/$1');
// offices
$routes->get('/offices', 'Offices::index');
$routes->get('/offices/view/(:num)', 'Offices::view/$1');
$routes->match(['get', 'post'], '/offices/edit/(:any)', 'Offices::edit/$1');
$routes->match(['get', 'post'], '/offices/create', 'Offices::edit/0');
// sitecontact
$routes->match(['get', 'post'],'/sitecontact/edit/(:num)', 'Sites::sitecontact_edit/$1');
$routes->get('/sitecontact/getEmail_1/(:num)', 'Sites::sitecontact_getEmail_1/$1');
$routes->get('/sitecontact/newrow', 'Sites::sitecontact_newrow');
// vendors
$routes->get('/vendors', 'Vendors::index');
$routes->get('/vendors/toggle/(:num)', 'Vendors::toggle/$1');
$routes->match(['get', 'post'], '/vendors/edit/(:any)', 'Vendors::edit/$1');
$routes->match(['get', 'post'], '/vendors/create', 'Vendors::create');
// producttype
$routes->get('/producttype', 'ProductType::index');
$routes->match(['get','post'],'/producttype/edit/(:num)', 'ProductType::edit/$1');
$routes->match(['get','post'],'/producttype/create', 'ProductType::create');
// productservice
$routes->get('/productservice', 'ProductService::index');
$routes->match(['get','post'],'/productservice/edit/(:num)', 'ProductService::edit/$1');
$routes->match(['get','post'],'/productservice/create', 'ProductService::create');
// productalias
$routes->match(['get','post'],'/productalias', 'ProductAlias::index');
$routes->match(['get','post'],'/productalias/edit/(:num)', 'ProductAlias::edit/$1');
$routes->match(['get','post'],'/productalias/create', 'ProductAlias::create');
// productcatalog
$routes->match(['get','post'],'/productcatalog', 'ProductCatalog::index');
$routes->match(['get','post'],'/productcatalog/edit/(:num)', 'ProductCatalog::edit/$1');
$routes->match(['get','post'],'/productcatalog/create', 'ProductCatalog::create');
// producttemp
$routes->get('/producttemp', 'ProductTemp::index');
$routes->get('/producttemp/getdata/(:num)', 'ProductTemp::getdata/$1');
$routes->post('/producttemp/edit', 'ProductTemp::edit');
$routes->post('/producttemp/validate', 'ProductTemp::validateItem');
$routes->post('/producttemp/delete/(:num)', 'ProductTemp::deleteItem/$1');

//unitgroup
$routes->match(['get','post'], '/unitgroup/', 'UnitGroup::index');
$routes->match(['get','post'], '/unitgroup/edit/(:num)', 'UnitGroup::edit/$1');
$routes->match(['get','post'], '/unitgroup/create', 'UnitGroup::edit/0');
$routes->get('/unitgroup/toggle/(:num)', 'UnitGroup::toggle/$1');

// products
$routes->match(['get','post'],'/products', 'Products::index');
$routes->get('/products/view/(:num)', 'Products::view/$1');
$routes->match(['get','post'],'/products/edit/(:num)', 'Products::edit/$1');
$routes->match(['get','post'],'/products/create', 'Products::edit/0');
$routes->match(['get','post'],'/products/log/edit/(:num)', 'Products::productslog_edit/$1');
$routes->match(['get','post'],'/products/movesite/(:num)', 'Products::movesite/$1');
$routes->match(['get','post'],'/products/changeowner/(:num)', 'Products::changeowner/$1');
$routes->match(['get','post'],'/products/upgrade/(:num)', 'Products::upgrade/$1');
$routes->post('/products/log/delete', 'Products::productslog_delete');
$routes->get('/products/export', 'Products::exportdata');
// users
$routes->get('/users', 'Users::index');
$routes->get('/users/view/(:num)', 'Users::view/$1');
$routes->match(['get','post'],'/users/create', 'Users::edit/0');
$routes->match(['get','post'],'/users/edit/(:num)', 'Users::edit/$1');
$routes->match(['get','post'],'/users/edit_password/(:num)', 'Users::edit_password/$1');
$routes->get('/users/toggle/(:num)', 'Users::toggle/$1');
$routes->match(['get','post'],'/users/role/edit/(:num)', 'Users::edit_role/$1');
$routes->match(['get','post'],'/users/log/edit/(:num)', 'Users::users_log_edit/$1');
$routes->get('/users/log/delete/(:num)', 'Users::users_log_delete/$1');
// userpos
$routes->get('/userposition', 'UserPosition::index');
$routes->match(['get','post'],'/userposition/create', 'UserPosition::create');
$routes->match(['get','post'],'/userposition/edit/(:num)', 'UserPosition::edit/$1');
// userdept
$routes->get('/userdepartment', 'UserDepartment::index');
$routes->match(['get','post'],'/userdepartment/create', 'UserDepartment::create');
$routes->match(['get','post'],'/userdepartment/edit/(:num)', 'UserDepartment::edit/$1');
// activity type
$routes->get('/acttype', 'ActType::index');
$routes->match(['get','post'],'/acttype/create', 'ActType::create');
$routes->match(['get','post'],'/acttype/edit/(:num)', 'ActType::edit/$1');
// activity text
$routes->get('/acttext', 'ActText::index');
$routes->get('/acttext/toggle/(:num)', 'ActText::toggle/$1');
$routes->match(['get','post'],'/acttext/create', 'ActText::create');
$routes->match(['get','post'],'/acttext/edit/(:num)', 'ActText::edit/$1');
// activities
$routes->match(['get','post'],'/activities/', 'Activities::index');
// $routes->get('/activities/index/getproduct/(:num)', 'Activities::index_getproduct/$1');
$routes->get('/activities/index/getproduct/(:any)/(:any)', 'Activities::index_getproduct/$1/$2');
$routes->get('/activities/detail/(:num)', 'Activities::detail/$1');
$routes->get('/activities/servicereport/(:num)', 'Activities::servicereport/$1');
$routes->get('/activities/suspend/(:num)', 'Activities::suspend/$1');
$routes->get('/activities/disable/(:num)', 'Activities::disable/$1');
// $routes->get('/activities/delete/(:num)', 'Activities::delete/$1');
$routes->match(['get','post'],'/activities/save', 'Activities::save');
$routes->post('/activities/upload', 'Activities::upload');
$routes->get('/activities/getproduct/(:num)', 'Activities::getproduct/$1/$2/$3');
$routes->get('/activities/getvendor/(:num)', 'Activities::getvendor/$1');
$routes->get('/activities/getconsumable/(:num)', 'Activities::getconsumable/$1');
$routes->get('/activities/getcontact/(:num)', 'Activities::getcontact/$1');
$routes->get('/activities/newtextarea', 'Activities::newtextarea');
$routes->get('/activities/activitiesproduct/(:num)', 'Activities::activitiesproduct/$1');
$routes->get('/activities/dummy', 'Activities::dummy');
$routes->match(['get','post'],'/activities/create', 'Activities::edit/0');
$routes->match(['get','post'],'/activities/refer/(:num)', 'Activities::createrefer/$1');
$routes->match(['get','post'],'/activities/savesend', 'Activities::savesend');
$routes->match(['get','post'],'/activities/edit/(:num)', 'Activities::edit/$1');
$routes->match(['get','post'],'/activities/editsend', 'Activities::editsend');
$routes->match(['get','post'],'/activities/count', 'Activities::count');
$routes->match(['get','post'],'/activities/export', 'Activities::export');
$routes->match(['get','post'],'/activities/compose/(:num)', 'Activities::email_compose/$1');
$routes->get('/testemail','Activites::email_test');

// contacts
$routes->get('/contacts', 'Contacts::index');
$routes->get('/contacts/view/(:num)', 'Contacts::view/$1');
$routes->match(['get','post'],'/contacts/edit/(:num)', 'Contacts::edit/$1');
$routes->match(['get','post'],'/contacts/create', 'Contacts::edit/0');

// emails
$routes->get('/emails', 'Emails::index');
$routes->get('/emails/toggle/(:num)', 'Emails::toggle/$1');
$routes->match(['get','post'],'/emails/edit/(:num)', 'Emails::edit/$1');
$routes->match(['get','post'],'/emails/create', 'Emails::edit/0');

// BUGS
$routes->get('/bugs', 'Bugs::index');
$routes->match(['get','post'],'/bugs/count', 'Bugs::count');
$routes->get('/bugs/toggle_close/(:num)', 'Bugs::toggle_close/$1');
$routes->get('/bugs/toggle_pending/(:num)', 'Bugs::toggle_pending/$1');
$routes->get('/bugs/toggle_reopen/(:num)', 'Bugs::toggle_reopen/$1');
$routes->get('/bugs/toggle_suspend/(:num)', 'Bugs::toggle_suspend/$1');
$routes->match(['get', 'post'], '/bugs/create', 'Bugs::create');
$routes->match(['get','post'], '/bugs/view/(:num)', 'Bugs::view/$1');
$routes->match(['get', 'post'], '/bugs/edit/(:any)', 'Bugs::edit/$1');
// $routes->get('/bugs/delete/(:num)', 'Bugs::delete/$1');

// GuideBooks
$routes->get('/guidebook', 'Guidebook::index');
$routes->match(['get', 'post'], '/guidebook/create', 'Guidebook::create');
$routes->get('/guidebook/view/(:num)', 'Guidebook::view/$1');
$routes->match(['get', 'post'], '/guidebook/edit/(:any)', 'Guidebook::edit/$1');
$routes->get('/guidebook/delete/(:num)', 'Guidebook::delete/$1');


// Certificates
$routes->group('certificates', function($routes) {

    // Untuk Index Tiap Menu
    $routes->get('maintenance', 'Certificates::maintenanceIndex'); // OK
    // $routes->get('installation', 'Certificates::installationIndex'); // OK
    // $routes->get('training', 'Certificates::trainingIndex'); // OK
    // $routes->get('calibration', 'Certificates::calibrateIndex'); // OK

    // Untuk Get API
    $routes->get('api/getindexmaintenance', 'Certificates::getDataIndexMaintenance'); // OK
    // $routes->get('api/getindexinstallation', 'Certificates::getDataIndexInstallation'); // OK
    // $routes->get('api/getindextraining', 'Certificates::getDataIndexTraining'); // OK
    // $routes->get('api/getindexcalibrate', 'Certificates::getDataIndexCalibrate');

    $routes->post('api/showmaintenance', 'Certificates::showDataMaintenance'); // OK

    // Untuk Preview Cerificate 
    $routes->get('maintenance/show/(:any)', 'Certificates::createMaintenancePreview/$1'); // OK
    // $routes->get('installation/show/(:any)', 'Certificates::createInstallationPreview/$1'); // OK
    // $routes->get('training/show/(:any)', 'Certificates::createTrainingPreview/$1'); // OK
    // $routes->get('calibration/show/(:any)/(:any)', 'Certificates::createCalibratePreview/$1/$2');

    $routes->post('api/validatecertificate', 'Certificates::validateCertificate'); // OK

    $routes->get('maintenance/number/$1', 'Certificates::getMaintenanceCertificate'); // OK

    $routes->get('number/(:segment)', 'Certificates::view/$1');
    
});



// Groups
$routes->get('/mailgroups', 'Mailgroups::index');
$routes->match(['get', 'post'], '/mailgroups/create', 'Mailgroups::edit/0');
$routes->match(['get', 'post'], '/mailgroups/edit/(:any)', 'Mailgroups::edit/$1');

//BUGS Comment
$routes->match(['get', 'post'], '/bugcomment/edit/(:any)', 'BugComment::edit/$1');
$routes->get('/bugcomment/delete/(:num)/(:num)', 'BugComment::delete/$1/$2');

//invcounters
$routes->get('/invcounters', 'InvCounters::index');
$routes->match(['get', 'post'], '/invcounters/create', 'InvCounters::edit/0');
$routes->match(['get', 'post'], '/invcounters/edit/(:any)', 'InvCounters::edit/$1');

//invtransactions
$routes->match(['get','post'],'/invtrans', 'Activities::invtrans_index');
$routes->match(['get','post'],'/invtrans/view/itd/(:any)', 'InvTrans::view_itd/$1');
$routes->match(['get','post'],'/invtrans/view/act/(:any)', 'InvTrans::view_act/$1');
$routes->match(['get','post'],'/invtrans/create', 'InvTrans::edit/0');
$routes->match(['get','post'],'/invtrans/edit/(:any)', 'InvTrans::edit/$1');
$routes->match(['get','post'],'/invtrans/user/(:any)', 'InvTrans::index_user/$1');
$routes->match(['get','post'],'/invtrans/reportusage/', 'InvTrans::reportusage/$1');

//LQMS
/*
$routes->match(['get','post'],'/lqms', 'Lqms::index');
$routes->post('/lqms/postdata', 'Lqms::postdata');
$routes->get('/lqms/log_clear', 'Lqms::log_clear');
$routes->get('/lqms/log/delete/(:any)', 'Lqms::log_delete/$1');
*/

/*
// Kanban
$routes->get('/kanban', 'Kanban::index');
$routes->get('/kanban/view/(:any)', 'Kanban::view/$1');
$routes->match(['get','post'],'/kanban/board/create/', 'Kanban::board_edit/0');
$routes->match(['get','post'],'/kanban/board/edit/(:any)', 'Kanban::board_edit/$1');
$routes->match(['get','post'],'/kanban/list/edit/(:any)', 'Kanban::list_edit/$1');
$routes->match(['get','post'],'/kanban/card/create/(:any)', 'Kanban::card_edit/$1/0');
$routes->match(['get','post'],'/kanban/card/edit/(:any)/(:any)', 'Kanban::card_edit/$1/$2');
$routes->get('/kanban/card/move/(:any)/(:any)', 'Kanban::card_move/$1/$2');
*/

// Key
$routes->group('', ['filter' => 'cors'], function($routes) {
    $routes->get('/key/key', 'Key::index');
    $routes->post('/key/data', 'Key::data');
});

// REST API
$routes->get('/api/zones', 'Api\ZonesApi::getAll');
$routes->get('/api/contacts', 'Api\ContactsApi::getAll');
// $routes->get('/api/provinces', 'Api\ZonesApi::getProvinces');
// $routes->get('/api/cities', 'Api\ZonesApi::getCities');
$routes->get('/api/getProductAlias', 'Api::getProductAlias'); 
$routes->get('/api/getProductSites', 'Api::getProductSites'); 
// $routes->get('/api/getProvinces', 'Api::getProvinces'); 
// $routes->get('/api/getCities', 'Api::getCities'); 


//CLQMS
// $routes->get('/clqms', 'Clqms::index'); // for CLQMS Inst select
/*
 * --------------------------------------------------------------------
 * Additional Routing
 * --------------------------------------------------------------------
 *
 * There will often be times that you need additional routing and you
 * need it to be able to override any defaults in this file. Environment
 * based routes is one such time. require() additional route files here
 * to make that happen.
 *
 * You will have access to the $routes object within that file without
 * needing to reload it.
 */
// if (is_file(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php')) {
//     require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
// }