<?php
 namespace VnChocola\Module\Api;
 use TCMS\Module;
 use Route;
 use Model;
 use LayoutData;
 use ROLE_ENUM;
 use TCMS\TException;
 class Customers extends Module {
 protected function initialize() {
 }
 protected function registerRoutes() {
 Route::get('/customers', 'IndexController', 'getList')->name('index');
 Route::post('/customers/create', 'IndexController', 'create')->name('create');
 Route::post('/customers/update', 'IndexController', 'update')->name('update');
 Route::post('/customers/delete', 'IndexController', 'delete')->name('delete');
 Route::post('/customers/searchFrm','IndexController','searchFrm')->name("searchFrm");
 Route::post('/customers/searchWidthField','IndexController','searchWidthField')->name("searchWith");
 Route::post('/customers/searchWithCar','IndexController','searchWithCar')->name("searchWith");
 Route::post('/customers/searchWithCarField','IndexController','searchWithCarField')->name("searchWith");
 Route::get('/customers/searchWithKey','IndexController','searchWithKey')->name("searchWithKey");
 Route::get('/customers/searchWithPlateNumber', 'IndexController', 'searchWithPlateNumber')->name('searchWithPlate');
 Route::post('/customers/check_code', 'IndexController', 'check_code')->name('check_code');
 Route::post('/customers/get_code', 'IndexController', 'get_code')->name('get_code');
 Route::get('/customers/{id}', 'IndexController', 'find')->name('find');
 Route::post('/customers/data', 'IndexController', 'LoadData')->name('data');
 Route::post('/customers/getCustomer','IndexController','getCustomer')->name("getCustomer");
 Route::get('/customers/getCustomer','IndexController','getCustomer')->name("getCustomer");
 Route::post('/customers/updateCusCommonMemo','IndexController','updateCusCommonMemo')->name("updateCusCommonMemo");
 Route::post('/customers/updateCusNotifyVisit','IndexController','updateCusNotifyVisit')->name("updateCusNotifyVisit");
 }
 public function registerComponent() {
 Model::add('CustomersModel', \VnChocola\Model\CustomersModel::class, true);
 Model::add('CarsInfoModel', \VnChocola\Model\CarsInfoModel::class, true);
 Model::add('VisitCustomersModel', \VnChocola\Model\VisitCustomersModel::class, true);
 Model::add('BranchsModel', \VnChocola\Model\BranchsModel::class, true);
 Model::add('CitysModel', \VnChocola\Model\CitysModel::class, true);
 Model::add('DistrictsModel', \VnChocola\Model\DistrictsModel::class, true);
 Model::add('PositionsModel', \VnChocola\Model\PositionsModel::class, true);
 Model::add('CompanyTypesModel', \VnChocola\Model\CompanyTypesModel::class, true);
 Model::add('StaffsModel', \VnChocola\Model\StaffsModel::class, true);
 Model::add('CarsModel', \VnChocola\Model\CarsModel::class, true);
 Model::add('CodeWorksModel', \VnChocola\Model\CodeWorksModel::class, true);
 Model::add('PurposesModel', \VnChocola\Model\PurposesModel::class, true);
 Model::add('CarCompartmentsModel', \VnChocola\Model\CarCompartmentsModel::class, true);
 Model::add('BranchsModel', \VnChocola\Model\BranchsModel::class, true);
 }
 public function boot() {
 }
 public function middleware(string $routeName, $auth) {
 switch($routeName) {
 case 'data': case 'index': case 'searchFrm': case 'searchWith': case 'getCustomer': case 'updateCusCommonMemo': case 'updateCusNotifyVisit': case 'find': return $auth->hasRole(\RoleGlobal::$role->viewCustomer);
 break;
 case 'create': case 'check_code': case 'get_code': return $auth->hasRole(\RoleGlobal::$role->createCustomer);
 break;
 case 'update': return $auth->hasRole(\RoleGlobal::$role->updateCustomer);
 break;
 case 'delete': return $auth->hasRole(\RoleGlobal::$role->deleteCustomer);
 break;
 case 'searchWithKey': case 'searchWithPlate': if(!$auth->hasRole(\RoleGlobal::$role->viewCustomer)) {
 throw new TException(lang('unauthorized.customer'), 401);
 }
 break;
 default: return false;
 }
 }
 }
