<?php
//Auth::routes();
#Installation script Routes
use Illuminate\Support\Facades\Route;
Route::group(array('prefix'=>'install','middleware'=>'install'),function() {
    Route::get('/','InstallController@index');
    Route::get('/database','InstallController@getDatabase');
    Route::post('/database','InstallController@postDatabase');
    Route::get('/user','InstallController@getUser');
    Route::post('/user','InstallController@postUser');
});

Route::group(['middleware' => 'install'], function(){
    Route::group(['prefix'=>'clientarea'],function(){
        Route::get('login', 'ClientArea\Auth\AuthController@getLogin')->name('client_login');
        Route::post('login', 'ClientArea\Auth\AuthController@postLogin');
        Route::get('logout', 'ClientArea\Auth\AuthController@getLogout')->name('client_logout');
        // Password Reset Routes...
        Route::get('password/reset', 'ClientArea\Auth\ForgotPasswordController@showLinkRequestForm');
        Route::post('password/email', 'ClientArea\Auth\ForgotPasswordController@sendResetLinkEmail');
        Route::get('password/reset/{token}', 'ClientArea\Auth\ResetPasswordController@showResetForm');
        Route::post('password/reset', 'ClientArea\Auth\ResetPasswordController@reset');
        Route::group(['middleware' => 'client'], function() {
            Route::get('/', 'ClientArea\HomeController@index');
            Route::get('home', 'ClientArea\HomeController@index')->name('client_dashboard');
            Route::resource('cinvoices', 'ClientArea\InvoicesController', array('only' => array('index', 'show')));
            Route::resource('cestimates', 'ClientArea\EstimatesController', array('only' => array('index', 'show')));
            Route::resource('cpayments', 'ClientArea\PaymentsController', ['only' => ['index', 'show']]);
            Route::post('getCheckout', ['as'=>'getCheckout','uses'=>'ClientArea\CheckoutController@getCheckout']);
            Route::get('getDone', ['as'=>'getDone','uses'=>'ClientArea\CheckoutController@getDone']);
            Route::get('getCancel/{id}', ['as'=>'getCancel','uses'=>'ClientArea\CheckoutController@getCancel']);
            Route::post('paypal_notify', ['as'=>'paypal_notify','uses'=>'ClientArea\CheckoutController@paypalNotify']);
            Route::get('stripecheckout/{id}', ['as'=>'stripecheckout','uses'=>'ClientArea\CheckoutController@stripeCheckout']);
            Route::post('stripecheckout', ['as'=>'stripesuccess','uses'=>'ClientArea\CheckoutController@stripeSuccess']);
            Route::get('payment_methods/{invoice_id}', ['uses' => 'ClientArea\PaymentMethodsController@index'])->name('client.invoice.pay');
            Route::get('cprofile', ['uses' => 'ClientArea\ProfileController@edit'])->name('client.getprofile');
            Route::post('cprofile', ['uses' => 'ClientArea\ProfileController@update'])->name('client.postprofile');
            Route::get('estimatepdf/{id}', 'ClientArea\EstimatesController@estimatePdf')->name('cestimate_pdf');
            Route::get('invoicepdf/{id}', 'ClientArea\InvoicesController@invoicePdf')->name('cinvoice_pdf');
            Route::get('lang/{lang}', ['as'=>'client_lang_switch', 'uses'=>'LanguageController@switchLang']);
            # reports resource
            Route::group(array('prefix'=>'reports'),function(){
                Route::get('/', 'ClientArea\ReportsController@index');
                Route::post('general', 'ClientArea\ReportsController@general_summary');
                Route::post('payment_summary', 'ClientArea\ReportsController@payment_summary');
                Route::post('client_statement', 'ClientArea\ReportsController@client_statement');
                Route::post('invoices_report', 'ClientArea\ReportsController@invoices_report');
            });
        });
    });
    Route::get('login', 'Auth\AuthController@showLoginForm')->name('admin_login');
    Route::post('login', 'Auth\AuthController@postLogin');
    Route::get('logout', 'Auth\AuthController@getLogout')->name('admin_logout');
    // Password Reset Routes...
    Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm');
    Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');
    Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
    Route::post('password/reset', 'Auth\ResetPasswordController@reset');
    Route::get('recurring', 'RecurringInvoicesController@index');
    Route::group(['middleware' => 'auth'], function(){
        #home controller
        Route::get('/',   'HomeController@index')->name('home');
        Route::get('home','HomeController@index');
        #Resources Routes
        Route::resources([
            'users'     => 'UsersController',
            'clients'   => 'ClientsController',
            'invoices'  => 'InvoicesController',
            'estimates' => 'EstimatesController',
            'payments'  => 'PaymentsController'
        ]);
        #Grouped Routes
        Route::group(['prefix'=>'settings'],function(){
            Route::resource('company', 'SettingsController', ['only' => ['index', 'store', 'update']])->names('settings.company');
            Route::resource('invoice', 'InvoiceSettingsController', ['only' => ['index', 'store', 'update']])->names('settings.invoice');
            Route::resource('email', 'EmailSettingsController', ['only' => ['index', 'store', 'update']])->names('settings.email');
            Route::resource('estimate', 'EstimateSettingsController', ['only' => ['index', 'store', 'update']])->names('settings.estimate');
            Route::resource('tax', 'TaxSettingsController')->names('settings.tax');
            Route::resource('templates', 'TemplatesController', ['only' => ['index','show', 'store', 'update']])->names('settings.template');
            Route::resource('number', 'NumberSettingsController', ['only' => ['index', 'store', 'update']])->names('settings.number');
            Route::resource('payment', 'PaymentMethodsController', ['except' => ['show']])->names('settings.payment');
            Route::resource('gateways', 'PaymentGatewayController',['only' => ['index', 'store', 'update']])->names('settings.gateways');
            Route::resource('currency', 'CurrencyController', ['except' => ['show']])->names('settings.currency');
            Route::resource('roles', 'RolesController')->names('settings.role');
            Route::resource('permissions', 'PermissionsController', ['except' => ['show', 'create']])->names('settings.permission');
            Route::resource('translations', 'TranslationsController')->names('settings.translation');
            Route::post('assignPermission', 'RolesController@assignPermission');
            Route::post('paypal_details', 'PaymentMethodsController@postPaypalDetails');
            Route::post('stripe_details', 'PaymentMethodsController@postStripeDetails');
            Route::get('update_exchange_rates', ['as'=>'update_exchange_rates','uses'=>'CurrencyController@updateCurrencyRates']);
            Route::post('/verify','InstallController@postVerify');
            Route::post('currency_key', 'CurrencyController@save_api_key')->name('post_currency_key');
        });
        # expenses resource
        Route::group(array('prefix'=>'expenses'),function(){
            Route::resource('list', 'ExpensesController')->names('expenses');
            Route::resource('category', 'ExpenseCategoryController')->names('expenses.category');
        });
        # products resource
        Route::group(array('prefix'=>'products'),function(){
            Route::resource('list', 'ProductsController')->names('products');
            Route::resource('category', 'ProductCategoryController')->names('products.category');
        });
        # estimates resource
        Route::group(array('prefix'=>'estimates'),function(){
            Route::post('deleteItem', 'EstimatesController@deleteItem');
            Route::get('pdf/{id}', 'EstimatesController@estimatePdf')->name('estimate_pdf');
            Route::post('makeInvoice', 'EstimatesController@makeInvoice');
            Route::get('send/{id}', 'EstimatesController@send_modal')->name('estimate_send_modal');
            Route::post('send', 'EstimatesController@send')->name('email_estimate');
        });
        # invoices resource
        Route::group(array('prefix'=>'invoices'),function(){
            Route::post('deleteItem', 'InvoicesController@deleteItem');
            Route::post('ajaxSearch', 'InvoicesController@ajaxSearch');
            Route::get('pdf/{id}', 'InvoicesController@invoicePdf')->name('invoice_pdf');;
            Route::get('send/{id}', 'InvoicesController@send_modal')->name('invoice.send_modal');
            Route::post('send', 'InvoicesController@send')->name('email_invoice');
        });
        # reports resource
        Route::group(array('prefix'=>'reports'),function(){
            Route::get('/', 'ReportsController@index');
            Route::post('general', 'ReportsController@general_summary');
            Route::post('payment_summary', 'ReportsController@payment_summary');
            Route::post('client_statement', 'ReportsController@client_statement');
            Route::post('invoices_report', 'ReportsController@invoices_report');
            Route::post('expenses_report', 'ReportsController@expenses_report');
        });
        # products custom routes
        Route::get('products_modal', 'ProductsController@products_modal')->name('products.modal');
        Route::post('process_products_selections', 'ProductsController@process_products_selections')->name('products.process_selection');
        # Profile
        Route::get('profile', ['uses' => 'ProfileController@edit'])->name('users.profile');
        Route::get('lang/{lang}', ['as'=>'admin_lang_switch', 'uses'=>'LanguageController@switchLang']);
        Route::post('profile', ['uses' => 'ProfileController@update']);
        Route::post('reports/ajaxData', 'ReportsController@ajaxData');
        #translations routes
        Route::get('language_translations/{groupKey}/{locale}', 'LanguageTranslationsController@getIndex')->where('groupKey', '.*')->name('language_translations');
    });
});