<?php
use Illuminate\Support\Facades\Route;

use App\Http\Controllers\ExcelProcessingController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// Route::get('/', function () {
//     return view('welcome');
// });

// Route::get('excel', 'ExcelProcessingController@inddex');
/*
Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth'])->name('dashboard');
*/

//require __DIR__.'/auth.php';

Route::post('/tokens/create', function (Request $request) {
    return ['token' => $request->user()->createToken('api-token')->plainTextToken];
});

Route::get('/docs/api', function () {
    return view('api-docs');
});
Route::get('graph', 'MerchantController@merchant_transactions_graph');
// Route::get('testmattermost', 'UtilityController@mattermosttest');



Route::get('testing', function(){
    $ucm_response = 'here at the wall ' . time();
    $pop = file_put_contents("/var/www/public/airtime_sales_portal/public/logs/" . date("Y_m_d_") . "sms_responses.txt", $ucm_response . PHP_EOL, FILE_APPEND);
    dd($pop);
});
Route::group(['middleware' => ['login']], function () {

    Route::get('/login', 'LoginController@login_page');

    Route::post('login_user','LoginController@login_user');

    Route::get('add_user','LoginController@add_user');

    //Route::get('register', 'LoginController@register_page');

    Route::post('reset-password', 'LoginController@reset_password');

    Route::get('forgot-password', 'LoginController@forgot_page');

    Route::post('send-reset-mail', 'LoginController@sendResetMail');

    Route::get('confirm-mail', 'LoginController@confirmMail');

});


Route::get('/logout', 'LoginController@logout')->middleware('logout');


/**
 * Admin Route
 */

Route::get('/', 'LandingPageController@index');

Route::get('admin', 'DashboardController@index')->middleware('admin');
Route::get('dealer', 'OrganisationsController@landing')->middleware('organisation');

Route::group(['middleware' => ['admin'], 'prefix' => 'admin'], function () {
    Route::get('/', 'DashboardController@index')->name('login');
    Route::get('organisations/create', 'AdminController@createOrg');
    Route::get('organisations', 'AdminController@index');
    Route::get('merchants', 'AdminController@merchant_index');
    Route::post('organisation/store', 'AdminController@organisationStore');
    Route::put('organisation/update/{id}', 'AdminController@update')->name('admin.organisation.update');
    Route::put('merchants/update/{id}', 'AdminController@merchant_update')->name('admin.merchant.update');
    Route::post('organisation/userupdate', 'AdminController@userupdate')->name('admin.organisation.userupdate');
    Route::get('organisation/edit/{id}', 'AdminController@edit')->name('organisation.edit');
    Route::get('organisation/show/{id}', 'AdminController@show')->name('organisation.show');

    Route::get('merchants/edit/{id}', 'AdminController@merchant_edit')->name('organisation.edit');

    Route::get('organisation/useredit/{id}', 'AdminController@useredit')->name('organisation.useredit');
    // Route::get('organisation/delete/{id}', 'AdminController@destroy')->name('organisation.delete');
    // Route::get('organisations/enable/{id}', 'AdminController@enable');
    // Route::get('organisations/disable/{id}', 'AdminController@disable');
    Route::get('dealer-transactions', 'AdminController@AdminTransactions'); // sales from Super Admin to Dealers
    Route::get('admin-dealer-transactions', 'AdminController@getAdminTransactionsJson'); // sales from Super Admin to Dealers
    // Route::get('organisations/merchants', 'AdminController@getOrganisationMerchants');
    //organisations/transactions
    Route::resource('transaction', 'TransactionController');
    Route::resource('activity', 'ActivityController');
    Route::resource('topups', 'TopUpsController');
    Route::resource('users', 'UserController');
    Route::get('settings', 'SettingsController@index');
    
    Route::get('dealersales', 'AdminController@getDealerSales');
    Route::get('dealersales/all', 'AdminController@getTransactionsJson');


    Route::get('merchantsales', 'AdminController@getMerchantSales');
    Route::get('/users/disable/{id}', 'UserController@destroy');
});

/**
 * Merchant Section
 */

//Merchant Login
Route::get('/merchant/login', 'LoginController@merchant_login_page')->middleware('merchant-login');
Route::post('/merchant/login', 'LoginController@merchant_login')->middleware('merchant-login');
Route::get('/merchant/logout', 'LoginController@merchant_logout')->middleware('merchant-logout')->name('merchant.logout');

Route::get('/merchant/register', 'LoginController@show_merchant_register');
Route::post('/merchant/register', 'LoginController@merchant_register');
Route::get('/merchant/register-success', 'LoginController@register_success');
Route::post('/merchant/check-country', 'LoginController@checkSupportedCountry');


## Merchant Routes
Route::group(['middleware' => ['merchant'],'prefix' => 'merchant'], function () {
    // Route::get('/', 'DashboardController@merchant');
    Route::post('/pushrefunds', 'MerchantController@refundStore')->name('pushrefunds');

    Route::get('/change-pin', 'MerchantController@showchangepin');
    Route::get('/refunds', 'MerchantController@showrefund');
    Route::get('/transactions', 'MerchantController@transactions');
    Route::get('/dealertransactions', 'MerchantController@dealer_transactions');
    Route::get('/dealers', 'MerchantController@get_dealers');

    Route::get('transactions/all', 'MerchantController@getTransactionsJson');
    Route::get('dealertransactions/all', 'MerchantController@getDealerTransactionsJson');

    Route::get('dealerlist/all', 'MerchantController@getDealerListJson');

    Route::get('/', 'MerchantController@landing');
    Route::get('landing', 'MerchantController@landing');
    Route::post('change-pin', 'MerchantController@changePin');

    Route::get('/showtopup', 'MerchantController@showCustomerTopForm');
    Route::post('/topup', 'MerchantController@customerTopupStore');
    Route::get('activity', 'MerchantController@getActivity');
});


//Organisation Login
Route::post('organisation/resetpassword', 'OrganisationLoginController@resetpassword');
Route::get('organisation/reset-password', 'OrganisationLoginController@resetCreate');

Route::get('/organisation/login', 'OrganisationLoginController@login_page');
Route::get('/dealer/login', 'OrganisationLoginController@login_page');

Route::get('/dealer/register', 'OrganisationLoginController@register_page');
Route::post('/dealer/register', 'OrganisationLoginController@register');
Route::get('/dealer/register-success', 'OrganisationLoginController@register_success');


Route::post('/organisation/login', 'OrganisationLoginController@handleLogin');
Route::get('/organisation/logout', 'OrganisationLoginController@logout')->name('organisation.logout');

# Organisation/Dealer Routes
Route::group(['middleware' => ['organisation'],'prefix' => 'organisation'], function () {
    Route::get('/', 'OrganisationsController@landing');
    Route::get('landing', 'OrganisationsController@landing')->name('organisation.dashboard');
    Route::get('dashboard', 'OrganisationsController@landing');
    

    Route::get('/transactions', 'OrganisationsController@transactions');
    Route::get('transactions/all', 'OrganisationsController@getTransactionsJson');

    Route::get('/mytopups', 'OrganisationsController@mytopups');
    Route::get('mytopups/all', 'OrganisationsController@getMyTopUpsJson');

    Route::get('/merchants', 'OrganisationsController@index');
    Route::get('/merchants/create', 'OrganisationsController@create');

    Route::get('/showtopup', 'OrganisationsController@showCustomerTopForm');
    Route::post('/topup', 'OrganisationsController@merchantTopupStore')->name('dealer.topup');
    Route::get('/topupotp', 'OrganisationsController@merchantTopupOtpStore');

    //Merchant Controller
    Route::resource('merchant', 'MerchantController');

    Route::get('/merchant/enable/{id}', 'MerchantController@enable');
    Route::get('/merchant/delete/{id}', 'MerchantController@destroy');
    // Route::post('/reseller/add-topup', 'MerchantController@addTopUp');

    Route::get('/activity', 'OrganisationsController@getActivity')->name('organisation.activity');
    
});
