<?php

use Illuminate\Http\Request;
Use App\Rate;
Use App\SettingBeneficiary;
Use App\SettingCredit;
Use App\SettingSupplier;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
	return $request->user();
});

Route::get('rate', 'RateController@show');
//Route::middleware('auth:api')->get('/user', function (Request $request) {
//    return $request->user();
//});
Route::group(['middleware' => 'auth:api'], function () {
    Route::post('logout', 'Auth\LoginController@logout');
    
	/*Route for the booking */
	Route::get('booking/{book_id}', 'BookingController@show');
	Route::put('booking/{book_id}', 'BookingController@update');
	Route::delete('booking/{book_id}', 'BookingController@delete');
	Route::post('booking/', 'BookingController@store');
	Route::post('booking/calculation', 'BookingController@calculation');
	Route::get('booking/cancelled/list', 'BookingController@userCanceledBooking');
	Route::post('booking/{id}/cancel', 'BookingController@cancelBooking');
	Route::post('booking/{id}/upload-user-bankslip', 'BookingController@uploadbankslip');
    Route::post('booking/{id}/upload-po', 'BookingController@uploadPurchaseOrder');
    Route::post('booking/{id}/confirm-po', 'BookingController@confirmPurchaseOrder');
	Route::patch('booking/{id}/bankslip-amount', 'BookingController@updateBankSlipAmount');
	Route::post('booking/{book_id}/reject-bank-slip','BookingController@rejectBankSlip');
	Route::post('booking/{book_id}/approve-bank-slip','BookingController@approveBankSlip');
    Route::get('booking/', 'BookingController@index'); 
	Route::get('user-complete-booking', 'BookingController@userComplete');

	Route::get('user', 'UserController@show');
	Route::patch('settings/profile', 'Settings\ProfileController@update');
	Route::patch('settings/password', 'Settings\PasswordController@update');

	// New Invoice Routes
	Route::get('invoice/{id}', 'InvoiceController@show');
	Route::post('invoice/{id}', 'InvoiceController@create');
	Route::put('invoice/{id}', 'InvoiceController@edit');
	Route::get('invoice/{id}/po', 'InvoiceController@customerToCIEFPO');
	Route::get('invoice/{id}/do', 'InvoiceController@CIEFToCustomerDO');
	Route::get('invoice/{id}/invoice', 'InvoiceController@CIEFToCustomerInvoice');

	//Route::get('notification/user', 'NotificationController@getUserMessage');
	//Route::post('notification/read-notification/{notification_id}', 'NotificationController@readNotification');

	// for both user and admin
	Route::get('active-bank', 'SettingActiveBankController@index');	
	Route::put('setting-tax', 'SettingActiveBankController@index');
	Route::put('setting-billing-charge', 'SettingBillingChargeController@index');
	Route::get('malaysia-bank/{malaysiaBank}', 'SettingMalaysiaBankController@show');
});

Route::group(['middleware' => 'guest:api'], function () {
	
	Route::get('showinvoice', 'InvoiceController@showinvoice');
    Route::post('login', 'Auth\LoginController@login')->name('login');
    Route::post('register', 'Auth\RegisterController@create');
    Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLink');
    Route::post('password/reset', 'Auth\ResetPasswordController@reset');
	Route::post('oauth/{driver}', 'Auth\OAuthController@redirectToProvider');
	Route::get('oauth/{driver}/callback', 'Auth\OAuthController@handleProviderCallback')->name('oauth.callback');
});

Route::group(['middleware' => ['role:admin']], function() {
	Route::get('admin/booking/{userId?}', 'BookingController@adminIndex');
	Route::get('admin-complete-booking/{userId?}', 'BookingController@adminBookComplete');
	Route::get('admin/booking/{id}/details', 'BookingController@adminShow');
    Route::get('admin/cancelled/booking', 'BookingController@CancelledBookings');
    Route::post('admin/booking/{id}/cancel', 'BookingController@cancelBooking');
	Route::post('update-rate', 'RateController@store');
	Route::put('update-rate/{rate}', 'RateController@update');
	Route::delete('update-rate/{rate}', 'RateController@delete');
	Route::get('update-rate', 'RateController@index');

	Route::get('setting-credit', 'SettingCreditController@index');
	Route::put('setting-credit', 'SettingCreditController@update');

	Route::put('setting-active-bank', 'SettingActiveBankController@update');

	Route::put('setting-tax', 'SettingTaxRateController@update');

	Route::put('setting-billing-charge', 'SettingBillingChargeController@update');

	Route::get('setting-supplier', 'SettingSupplierController@index');
	Route::get('setting-supplier/{supplier}', 'SettingSupplierController@show');
	Route::post('setting-supplier', 'SettingSupplierController@store');
	Route::put('setting-supplier/{supplier}', 'SettingSupplierController@update');
	Route::delete('setting-supplier/{supplier}', 'SettingSupplierController@delete');

	Route::get('setting-beneficiary', 'SettingBeneficiaryController@index');
	Route::get('setting-beneficiary/{beneficiary}', 'SettingBeneficiaryController@show');
	Route::post('setting-beneficiary', 'SettingBeneficiaryController@store');
	Route::put('setting-beneficiary/{beneficiary}', 'SettingBeneficiaryController@update');
	Route::delete('setting-beneficiary/{beneficiary}', 'SettingBeneficiaryController@delete');

	Route::get('setting-malaysia-bank', 'SettingMalaysiaBankController@index');
	Route::post('setting-malaysia-bank', 'SettingMalaysiaBankController@store');
	Route::put('setting-malaysia-bank/{malaysiaBank}', 'SettingMalaysiaBankController@update');
	Route::delete('setting-malaysia-bank/{malaysiaBank}', 'SettingMalaysiaBankController@delete');
	Route::put('setting-malaysia-bank/status/{id}', 'SettingMalaysiaBankController@updateStatus');

	Route::get('setting-marking', 'MarkingController@index');
	Route::post('setting-marking', 'MarkingController@store');
	Route::get('setting-marking/{marking}', 'MarkingController@show');
	Route::put('setting-marking/{marking}', 'MarkingController@update');
	Route::delete('setting-marking/{marking}', 'MarkingController@delete');

	Route::get('supplier-booking', 'BookingSupplierController@index');
	Route::get('supplier-booking/{id}', 'BookingSupplierController@show');
	Route::post('supplier-booking', 'BookingSupplierController@store');
	Route::put('supplier-booking/{id}', 'BookingSupplierController@update');
	Route::post('booking/{id}/confirm-supplier', 'BookingController@confirmSupplier');

	// Route::get('notification', 'NotificationController@index');
	// Route::get('notification/{notification}', 'NotificationController@show');
	// Route::post('notification', 'NotificationController@store');
	// Route::put('notification/{notification}', 'NotificationController@update');
	// Route::delete('notification/{notification}', 'NotificationController@delete');

	Route::post('booking/{id}/upload-china-bankslip','ChinaBankSlipController@store');
	Route::patch('booking/{id}/update-china-bankslip','ChinaBankSlipController@update');
	Route::get('booking/{id}/po', 'BookingController@showPurchaseOrder');
	Route::post('booking/{id}/upload-invoice', 'BookingController@uploadInvoice');
	Route::post('booking/{id}/confirm-invoice', 'BookingController@confirmInvoice');
	
	// New routes for invoice
	
	Route::patch('invoice/{id}/status', 'InvoiceController@updateStatus');
	Route::get('invoice/{id}/supplierdo', 'InvoiceController@CIEFToSupplierDO');
	Route::post('invoice/{id}/comment', 'InvoiceController@postStatus');

	Route::get('admin/complete-orders', 'BookingController@adminShowCompletedOrders');
	// for both user and admin
	Route::get('setting-active-bank', 'SettingActiveBankController@index');	
	Route::get('setting-tax', 'SettingTaxRateController@index');
	Route::get('setting-billing-charge', 'SettingBillingChargeController@index');
	Route::get('setting-malaysia-bank/{malaysiaBank}', 'SettingMalaysiaBankController@show');	
	
});