<?php

use App\Http\Controllers\AdminController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\LogoutController;
use App\Http\Controllers\Auth\ResetPasswordController;
use App\Http\Controllers\ChangePasswordController;
use App\Http\Controllers\CompanyProfileController;
use App\Http\Controllers\CustomerController;
use App\Http\Controllers\DealerController;
use App\Http\Controllers\EzyPOSLicenseController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\MasterDealerController;
use App\Http\Controllers\OnlineEzyPOSBackupController;
use App\Http\Controllers\PaidAccountPaymentMethodController;
use App\Http\Controllers\PrivacyPolicyController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\SubDealerController;
use App\Http\Controllers\TrialAccountPaymentMethodController;
use App\Http\Controllers\TrialCompanyProfileController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

//Route::get('test', function () {
//
//    return Hash::make('sigma123');
//});
//
//
//Route::get('init', function () {
//    \Illuminate\Support\Facades\Artisan::call('app:db-demo');
//});

Route::get('clear-cache', function () {
    Artisan::call('cache:clear');
    Artisan::call('config:clear');
    Artisan::call('view:clear');

    return response('Cache is cleared');
});

Route::get('run-cache', function () {
    Artisan::call('config:cache');
    Artisan::call('route:cache');
    Artisan::call('view:cache');

    return response('Cache Done');
});


Route::get('/privacy-policy', [PrivacyPolicyController::class, 'index'])->name('privacy.policy');


//Route::get('/test', function () {
//
//    $password = Hash::make('0167782401');
//
//    return response($password);
//
//});

//Auth::routes();
Route::post('/auth/reset-password', [ResetPasswordController::class, 'resetPasswordByEmail'])->middleware('guest')->name('auth.reset-password');
Route::get('/reset-password/{token}', [ResetPasswordController::class, 'resetPasswordView'])->middleware('guest')->name('password.reset');
Route::post('/reset-password', [ResetPasswordController::class, 'validateResetPassword'])->middleware('guest')->name('password.update');


Route::group(['prefix' => 'master-dealer'], function () {
    Route::get('/login', [LoginController::class, 'showMasterDealerLoginForm'])->name('master-dealer.login-view');
    Route::post('/login', [LoginController::class, 'masterDealerLogin'])->name('master-dealer.login');
    Route::post('/logout', [LogoutController::class, 'masterDealerLogout'])->name('master-dealer.logout');
    Route::get('/password-reset', [ResetPasswordController::class, 'showMasterDealerResetForm'])->name('master-dealer.password.reset-form');
});

Route::group(['prefix' => 'dealer'], function () {
    Route::get('/login', [LoginController::class, 'showSubDealerLoginForm'])->name('sub-dealer.login-view');
    Route::post('/login', [LoginController::class, 'subDealerLogin'])->name('sub-dealer.login');
    Route::post('/logout', [LogoutController::class, 'subDealerLogout'])->name('sub-dealer.logout');
    Route::get('/password-reset', [ResetPasswordController::class, 'showSubDealerResetForm'])->name('sub-dealer.password.reset-form');
});


Route::group(['prefix' => 'admin'], function () {
    Route::get('/login', [LoginController::class, 'showAdminLoginForm'])->name('admin.login-view');
    Route::post('/login', [LoginController::class, 'adminLogin'])->name('admin.login');
    Route::post('/logout', [LogoutController::class, 'adminLogout'])->name('admin.logout');
    Route::get('/password-reset', [ResetPasswordController::class, 'showAdminResetForm'])->name('admin.password.reset-form');
});

Route::group(['prefix' => 'trial-account'], function () {
    Route::get('/login', [LoginController::class, 'showTrialLoginForm'])->name('trial-account.login-view');
    Route::post('/login', [LoginController::class, 'trialLogin'])->name('trial-account.login');
    Route::post('/logout', [LogoutController::class, 'trialLogout'])->name('trial-account.logout');
    Route::get('/password-reset', [ResetPasswordController::class, 'showTrialAccountResetForm'])->name('trial-account.password.reset-form');
});

Route::group(['prefix' => 'account'], function () {
    Route::get('/login', [LoginController::class, 'showPaidLoginForm'])->name('paid-account.login-view');
    Route::post('/login', [LoginController::class, 'paidLogin'])->name('paid-account.login');
    Route::post('/logout', [LogoutController::class, 'paidLogout'])->name('paid-account.logout');
    Route::get('/password-reset', [ResetPasswordController::class, 'showPaidAccountResetForm'])->name('paid-account.password.reset-form');
});


Route::get('/', [LoginController::class, 'redirectToDashboard']);

Route::group(['middleware' => 'auth:paid-account', 'prefix' => 'account'], function () {

    Route::get('/dashboard', [HomeController::class, 'index'])->name('paid-accounts.dashboard');

    Route::get('/company-profile', [CompanyProfileController::class, 'index'])->name('paid-accounts.company-profile');
    Route::put('/company-profile', [CompanyProfileController::class, 'update'])->name('paid-accounts.company-profile.update');

    Route::get('/change-password', [ChangePasswordController::class, 'paidAccountView'])->name('paid-accounts.change-password');
    Route::post('/change-password', [ChangePasswordController::class, 'paidAccountStore'])->name('paid-accounts.change-password.store');

    Route::get('/change-pin', [ChangePasswordController::class, 'paidAccountChangePIN'])->name('paid-accounts.change-pin');
    Route::post('/change-pin', [ChangePasswordController::class, 'paidAccountChangePINStore'])->name('paid-accounts.change-pin.store');

    Route::get('/payment-methods', [PaidAccountPaymentMethodController::class, 'index'])->name('paid-accounts.payments.index');
    Route::get('/payment-terminal', [PaidAccountPaymentMethodController::class, 'paymentTerminalView'])->name('paid-accounts.payments.terminals-view');
    Route::post('/payment-terminal', [PaidAccountPaymentMethodController::class, 'paymentTerminalStore'])->name('paid-accounts.payments.terminals-store');
    Route::get('/payment-methods/add', [PaidAccountPaymentMethodController::class, 'addPayment'])->name('paid-accounts.payments.add-view');
    Route::post('/payment-methods/add', [PaidAccountPaymentMethodController::class, 'store'])->name('paid-accounts.payments.store');
    Route::get('/payment-methods/edit/{id}', [PaidAccountPaymentMethodController::class, 'editPayment'])->name('paid-accounts.payments.edit-view');
    Route::post('/payment-methods/edit/{id}', [PaidAccountPaymentMethodController::class, 'update'])->name('paid-accounts.payments.update');
    Route::post('/payment-methods/delete', [PaidAccountPaymentMethodController::class, 'delete'])->name('paid-accounts.payments.delete');

});

Route::group(['middleware' => 'auth:trial-account', 'prefix' => 'trial-account'], function () {
    Route::get('/dashboard', [HomeController::class, 'index'])->name('trial-accounts.dashboard');

    Route::get('/company-profile', [TrialCompanyProfileController::class, 'index'])->name('trial-accounts.company-profile');
    Route::put('/company-profile', [TrialCompanyProfileController::class, 'update'])->name('trial-accounts.company-profile.update');

    Route::get('/change-password', [ChangePasswordController::class, 'trialAccountView'])->name('trial-accounts.change-password');
    Route::post('/change-password', [ChangePasswordController::class, 'trialAccountStore'])->name('trial-accounts.change-password.store');

    Route::get('/change-pin', [ChangePasswordController::class, 'trialAccountChangePIN'])->name('trial-accounts.change-pin');
    Route::post('/change-pin', [ChangePasswordController::class, 'trialAccountChangePINStore'])->name('trial-accounts.change-pin.store');


    Route::get('/payment-methods', [TrialAccountPaymentMethodController::class, 'index'])->name('trial-accounts.payments.index');
    Route::get('/payment-methods/add', [TrialAccountPaymentMethodController::class, 'addPayment'])->name('trial-accounts.payments.add-view');
    Route::post('/payment-methods/add', [TrialAccountPaymentMethodController::class, 'store'])->name('trial-accounts.payments.store');
    Route::get('/payment-methods/edit/{id}', [TrialAccountPaymentMethodController::class, 'editPayment'])->name('trial-accounts.payments.edit-view');
    Route::post('/payment-methods/edit/{id}', [TrialAccountPaymentMethodController::class, 'update'])->name('trial-accounts.payments.update');
    Route::post('/payment-methods/delete', [TrialAccountPaymentMethodController::class, 'delete'])->name('trial-accounts.payments.delete');
});


Route::group(['middleware' => 'auth:master-dealer', 'prefix' => 'master-dealer'], function () {
    Route::get('/dashboard', [HomeController::class, 'index'])->name('master-dealer.dashboard');

    Route::get('/prospects', [CustomerController::class, 'masterDealerShowProspect'])->name('master-dealer.prospects');
    Route::post('/prospects/transfer', [CustomerController::class, 'transferProspectToSubDealer'])->name('master-dealer.prospects.transfer');

    Route::get('/customers', [CustomerController::class, 'masterDealerShowCustomer'])->name('master-dealer.customers');

    Route::get('/dealers', [SubDealerController::class, 'index'])->name('master-dealer.dealers');
    Route::get('/dealers/add', [SubDealerController::class, 'addSubDealer'])->name('master-dealer.dealers.add-view');
    Route::post('/dealers/add', [SubDealerController::class, 'store'])->name('master-dealer.dealers.add');
    Route::post('/dealers/transfer-license', [SubDealerController::class, 'transferLicense'])->name('master-dealer.dealers.assign-license');

    Route::get('/change-password', [ChangePasswordController::class, 'masterDealerView'])->name('master-dealer.change-password');
    Route::post('/change-password', [ChangePasswordController::class, 'masterDealerStore'])->name('master-dealer.change-password.store');
});


Route::group(['middleware' => 'auth:sub-dealer', 'prefix' => 'dealer'], function () {
    Route::get('/dashboard', [HomeController::class, 'index'])->name('sub-dealer.dashboard');

    Route::get('/licenses', [EzyPOSLicenseController::class, 'subDealerLicense'])->name('sub-dealer.licenses');
    Route::get('/licenses/assign', [EzyPOSLicenseController::class, 'assignLicenseView'])->name('sub-dealer.licenses.assign-view');
    Route::post('/licenses/assign', [EzyPOSLicenseController::class, 'assignLicense'])->name('sub-dealer.licenses.assign');
    Route::post('/licenses/status', [EzyPOSLicenseController::class, 'updateLicenseStatus'])->name('sub-dealer.licenses.status');
    Route::post('/licenses/transfer', [EzyPOSLicenseController::class, 'transferLicense'])->name('sub-dealer.licenses.transfer');
    Route::post('/licenses/transfer-type', [EzyPOSLicenseController::class, 'transferLicenseType'])->name('sub-dealer.licenses.transfer-type');

    Route::get('/customers', [CustomerController::class, 'subDealerShowCustomer'])->name('sub-dealer.customers');
    Route::get('/customers/{customerId}', [SubDealerController::class, 'showCustomerInfo'])->name('sub-dealer.customers.info');

    Route::get('/trial-customers', [CustomerController::class, 'subDealerShowTrialCustomer'])->name('sub-dealer.trial-customers');
    Route::post('/trial-customers/contacted', [CustomerController::class, 'customerConnected'])->name('sub-dealer.trial-customers.contacted');

    Route::get('/change-password', [ChangePasswordController::class, 'subDealerView'])->name('sub-dealer.change-password');
    Route::post('/change-password', [ChangePasswordController::class, 'subDealerStore'])->name('sub-dealer.change-password.store');

});


Route::group(['middleware' => 'auth:admin', 'prefix' => 'admin'], function () {

    Route::get('/dashboard', [HomeController::class, 'index'])->name('admin.dashboard');

    Route::get('/customers', [CustomerController::class, 'index'])->name('admin.customers');

    Route::get('/dealers', [MasterDealerController::class, 'index'])->name('admin.dealers');
    Route::get('/dealers/add', [MasterDealerController::class, 'addDealer'])->name('admin.dealers.add-view');
    Route::post('/dealers/add', [MasterDealerController::class, 'store'])->name('admin.dealers.add');
    Route::post('/dealers/transfer-license', [MasterDealerController::class, 'transferLicense'])->name('admin.dealers.assign-license');

    Route::get('/sub-dealers', [SubDealerController::class, 'index'])->name('admin.sub-dealers');
});



