<?php defined('BASEPATH') OR exit('No direct script access allowed');

/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
|	example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
|	http://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are three reserved routes:
|
|	$route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
|	$route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
|	$route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route, but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples:	my-controller/index	-> my_controller/index
|		my-controller/my-method	-> my_controller/my_method
*/
$route['default_controller'] = 'FrontPage';

//CHECK: Should I limit everything to the specific methods? I.E: GET or POST
//       This would avoid POST working on pages which should be gotten via GET. Does it matter?

$route['user/signup']                = 'User/Auth/Signup';
$route['user/signup/(.*)']           = 'User/Auth/Signup/index/$1';
$route['user/forgot_password']       = 'User/Auth/Forgot_Password';
$route['user/reset_password/(.*)']   = 'User/Auth/Forgot_Password/reset_password/$1';
$route['user/login']                 = 'User/Auth/Login';
$route['user/logout']                = 'User/Auth/Logout';
$route['user/history']               = 'User/History';
$route['user/history/([0-9]+)']      = 'User/History/index/$1';
$route['user/history/export/(csv|json)'] = 'User/History/export/$1';
$route['user/favourites']            = 'User/Favourites';
$route['user/favourites/([0-9]+)']   = 'User/Favourites/index/$1';
$route['user/favourites/export/(csv|json)'] = 'User/Favourites/export/$1';
$route['user/options']               = 'User/Options';

$route['user/dashboard']      = 'User/Dashboard';
$route['user/dashboard_beta'] = 'User/DashboardBeta'; //TEMP

//usernames are limited to a-Z, 0-9, _ & - characters. 4min, 15 max length
$route['list/([a-zA-Z0-9_-]+)']              = 'User/PublicList/index/$1';
$route['list/([a-zA-Z0-9_-]+)\.([a-zA-Z]+)'] = 'User/PublicList/index/$1/$2';

$route['history/([0-9]+)']           = 'TitleHistory/index/$1';
$route['history/([0-9]+)/([0-9]+)']  = 'TitleHistory/index/$1/$2';

$route['update_status'] = 'UpdateStatus';

$route['api/internal/get_list']                                                      = 'API/Internal/GetList';
$route['api/internal/get_list/(all|reading|on-hold|plan-to-read|(custom(?:1|2|3)))'] = 'API/Internal/GetList/index/$1';

$route['ajax/username_check']['post'] = 'Ajax/UsernameCheck'; //rate limited
$route['ajax/get_apikey']             = 'Ajax/GetKey';
$route['ajax/get_apikey/restore']     = 'Ajax/GetKey/restore';
//$route['ajax/get_tracker']            = 'Ajax/Tracker/get';

$route['ajax/update_inline']['post']   = 'Ajax/TrackerInline/update';
$route['ajax/ignore_inline']['post']   = 'Ajax/TrackerInline/ignore';
$route['ajax/delete_inline']['post']   = 'Ajax/TrackerInline/delete';
$route['ajax/tag_update']['post']      = 'Ajax/TrackerInline/tag_update';
$route['ajax/mass_tag_update']['post'] = 'Ajax/TrackerInline/mass_tag_update';
$route['ajax/set_category']['post']    = 'Ajax/TrackerInline/set_category';
$route['ajax/hide_notice']['post']     = 'Ajax/TrackerInline/hide_notice';
$route['ajax/set_mal_id']['post']      = 'Ajax/TrackerInline/set_mal_id';

$route['export_list']                 = 'Ajax/TrackerInline/export';
//$route['import_list']['post']         = 'Ajax/TrackerInline/import';

$route['import_amr'] = 'Import_AMR';

$route['report_issue'] = 'ReportIssue';

$route['stats']       = 'Stats';
$route['help']        = 'Help';

$route['about']       = 'About';
$route['about/terms'] = 'About/terms';

$route['admin_panel'] = 'AdminPanel';
$route['admin_panel/update/normal'] = 'AdminPanel/update_normal';
$route['admin_panel/update/custom'] = 'AdminPanel/update_custom';
$route['admin_panel/update/titles'] = 'AdminPanel/update_titles';
$route['admin_panel/update_mal_id'] = 'AdminPanel/update_mal_id';
$route['admin_panel/populate_db']   = 'AdminPanel/populate_db';

/*** USERSCRIPT ROUTING ***/
$route['ajax/userscript/update']['post']     = 'Ajax/Userscript/update';
$route['ajax/userscript/favourite']['post']  = 'Ajax/Userscript/favourite';

$route['userscripts/sites/.*\.js']           = 'Ajax/Userscript/site_fallback';

/*** SPECIAL ROUTING ***/
if(is_cli()) {
	$route['admin/migrate']              = 'AdminCLI/migrate';

	$route['admin/update_series']        = 'AdminCLI/updateSeries';
	$route['admin/update_series_custom'] = 'AdminCLI/updateSeriesCustom';
	$route['admin/refollow_custom']      = 'AdminCLI/refollowCustom';

	$route['admin/test']                 = 'AdminCLI/testSite/do/nothing';
	$route['admin/test/(.*?)/(.*)']      = 'AdminCLI/testSite/$1/$2';
}

/*** DISALLOWED ROUTING ***/
// disallow everything else
//$route['(.*)']                 = 'error'; //for whatever stupid reason, (:any) doesn't work here

$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
