<?php

//All Sales Controllers are Here
use App\Http\Controllers\sales\AgentController;
use App\Http\Controllers\sales\ApplicationController;
use App\Http\Controllers\sales\DashboardController;
use App\Http\Controllers\sales\DepartmentAuth;
use App\Http\Controllers\sales\SaleController;
use App\Http\Controllers\sales\FundsController;
use App\Http\Controllers\sales\ProductListController;


//All MD Controllers are Here
use App\Http\Controllers\md\MdAgentController;
use App\Http\Controllers\md\MdApplicationController;
use App\Http\Controllers\md\MdDashboardController;
use App\Http\Controllers\md\MdDepartmentAuth;
use App\Http\Controllers\md\MdSaleController;
use App\Http\Controllers\md\MdFundsController;
use App\Http\Controllers\md\MdController;
use App\Http\Controllers\md\MdProductListController;

use App\Http\Controllers\Controller;
use App\Http\Controllers\md\FlatController;
use App\Http\Controllers\md\LocatinController;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Route;
use Spatie\Backup\Tasks\Backup\BackupJobFactory;


/*
|--------------------------------------------------------------------------
| Web Routes
|-----------------------------------@csrf-----------------
|
| 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('/pass', function(){
  $password = '123456789';
  $hash = bcrypt($password);
  dd($hash);
});

Route::get('/prods', function(){
    $allProds = DB::table('product_template')->get();
    dd($allProds);
});

Route::get('/mark', [ApplicationController::class, 'tableList']); // Using this to check tables on Postgress during weekend
Route::get('/', [DepartmentAuth::class, 'verify'])->name('index');
Route::get('/dashboard', [DashboardController::class, 'index'])->name('verify-auth');

//All MD routes are here
Route::prefix('md')->group(function () {

    Route::controller(LocatinController::class)->group(function () {
        Route::get('/all-location',  'allLocation')->name('all.location');
        Route::get('/add-location', 'addLocation')->name('add.location');
        Route::post('/store-location', 'storeLocation')->name('store.location');
    });

    Route::controller(MdFundsController::class)->group(function () {
    Route::get('/request-refund',  'requestRefund')->name('md-request-refund');
    Route::get('/refund-requests', 'refundRequests')->name('md-refund-requests');
    Route::get('/view-refund-request', 'refundRequest')->name('md-view-refund-request');
    Route::post('/submit-request-refund','submitRefund')->name('md-submit-request-refund');
    Route::get('/transfer-of-funds', 'transferOfFunds')->name('md-transfer-of-funds');
    Route::post('/transfer-funds', 'transferFunds')->name('md-transfer-funds');
    Route::get('/transfer-requests', 'transferRequests')->name('md-transfer-requests');
    Route::get('/view-transfer-request', 'transferRequest')->name('md-view-transfer-request');
});

Route::controller(MdController::class)->group(function () {
    Route::get('/pending-approvals', 'pendingApprovals')->name('md-pending-approvals');
    Route::post('/approve-handover', 'approveHandover')->name('md-approve-handover');
    Route::post('/generate-handover-certificate', 'generateHandoverCertificate')->name('md-generate-handover-certificate');
    Route::post('/download-handover-certificate', 'downloadHandoverCertificate')->name('md-download-handover-certificate');
    Route::post('/generate-clearance-certificate','downloadClearanceCertificate')->name('md-generate-clearance-certificate');
    Route::get('/change-code', 'accessCode')->name('change-code');
    Route::post('/submit-code', 'updateAccessCode')->name('submit-code');
});

Route::controller(MdAgentController::class)->group(function () {
    Route::get('/agents', 'agents')->name('md-agents');
    Route::get('/view_agent/{id}', 'viewAgentDetails')->name('md-view-agent-details');
});

Route::controller(MdApplicationController::class)->group(function () {
    Route::get('/view-application',  'viewApplications')->name('md-view-application');
    Route::post('/offer-preview', 'offerPreview')->name('md-offer-preview');
    Route::post('/send-offer', 'sendOfferEmail')->name('md-send.offer.email');
    Route::post('/discount-invoice-preview', 'discountInvoice')->name('md-discount-invoice-preview');
    Route::post('/send-offer', 'sendOfferEmail')->name('md-send.offer.email');
    Route::post('/get-house-types-and-amounts', 'getHouseTypesAndAmounts');
    Route::get('/get-projects', 'getProjects')->name('md-get-projects');
    Route::get('/all-applications',  'allApplications')->name('md-all-applications');
    Route::post('/form-receipt-preview', 'viewReceipt')->name('md-form-receipt-preview');

});

Route::controller(MdSaleController::class)->group(function () {
    Route::get('/sales-overview','salesOverview')->name('md-sales-overview');
    Route::get('/sales-access-code', 'accessCode')->name('md-sales.access.code');
    Route::post('/update-sales-access-code','updateAccessCode')->name('md-update-sales-access-code');
    Route::post('/view-sale-order', 'viewSaleOrder')->name('md-view-sale-order');
    Route::post('/view-payments', 'viewPayments')->name('md-view-payments');
    Route::post('/receipt-preview', 'viewReceipt')->name('md-receipt-preview');
    Route::post('/send-receipt', 'sendReceiptEmail')->name('md-send.receipt.email');
    Route::post('/preview-provisional-letter','provisionalLetterPreview')->name('md-preview-provisional-letter');
    Route::post('/preview-final-letter','finalLetterPreview')->name('md-preview-final-letter');
});

    Route::controller(MdProductListController::class)->group(function () {
    Route::get('/all-products', 'allProducts')->name('md-all_pproducts');
    Route::get('/add-product', 'addProduct')->name('add.product');
    Route::post('/store-product', 'storeProduct')->name('store.product');
});

Route::controller(FlatController::class)->group(function () {
    Route::get('/all-flat', 'allFlats')->name('all.flat');
    Route::get('/add-flats', 'addFlats')->name('add.flat');
    Route::post('/store-flats', 'storeFlats')->name('store.flat');
});

});




//All sales route are here
Route::prefix('sales')->group(function () {
    Route::post('/verify-auth', [DepartmentAuth::class, 'verifyAuth']);
    Route::controller(FundsController::class)->group(function () {
        Route::get('/request-refund', 'requestRefund')->name('request-refund');
        Route::get('/refund-requests',  'refundRequests')->name('refund-requests');
        Route::get('/view-refund-request', 'refundRequest')->name('view-refund-request');
        Route::post('/submit-request-refund', 'submitRefund')->name('submit-request-refund');
        Route::get('/transfer-of-funds', 'transferOfFunds')->name('transfer-of-funds');
        Route::post('/transfer-funds', 'transferFunds')->name('transfer-funds');
        Route::get('/transfer-requests', 'transferRequests')->name('transfer-requests');
        Route::get('/view-transfer-request', 'transferRequest')->name('view-transfer-request');
});

Route::controller(MdController::class)->group(function () {
    Route::post('/approve-handover', 'approveHandover')->name('approve-handover');
    Route::post('/generate-handover-certificate', 'generateHandoverCertificate')->name('generate-handover-certificate');
    Route::post('/download-handover-certificate', 'downloadHandoverCertificate')->name('download-handover-certificate');
    Route::post('/generate-clearance-certificate', 'downloadClearanceCertificate')->name('generate-clearance-certificate');
});

Route::controller(ApplicationController::class)->group(function () {
    Route::get('/view-application', 'viewApplications')->name('view-application');
    Route::get('/edit-application', 'editApplications')->name('edit-application');
    Route::post('/update-application', 'updateApplication')->name('update-application');
    Route::post('/offer-preview', 'offerPreview')->name('offer-preview');
    Route::post('/send-offer', 'sendOfferEmail')->name('send.offer.email');
    Route::post('/discount-invoice-preview', 'discountInvoice')->name('discount-invoice-preview');
    Route::post('/application-form', 'submitForm')->name('submit-form');
    Route::post('/get-house-types-and-amounts', 'getHouseTypesAndAmounts');
    Route::get('/get-product-details','getProductDetails');
    Route::get('/share-form-via-whatsapp', 'shareFormViaWhatsApp')->name('shareFormViaWhatsApp');
    Route::get('/get-projects', 'getProjects')->name('get.projects');
    Route::post('/upload-image', 'uploadImages')->name('upload-image');
    Route::get('/application-form', 'applicationForm')->name('application-form');
    Route::get('/all-applications', 'allApplications')->name('all-applications');
    Route::post('/form-receipt-preview', 'viewReceipt')->name('form-receipt-preview');
    Route::post('/send-offer', 'sendOfferEmail')->name('send.offer.email');
});

Route::controller(SaleController::class)->group(function () {
    Route::get('/sales-overview', 'salesOverview')->name('sales-overview');
    Route::get('/sales-access-code', 'accessCode')->name('sales.access.code');
    Route::post('/update-sales-access-code', 'updateAccessCode')->name('update-sales-access-code');
    Route::post('/view-sale-order', 'viewSaleOrder')->name('view-sale-order');
    Route::post('/view-payments', 'viewPayments')->name('view-payments');
    Route::post('/receipt-preview', 'viewReceipt')->name('receipt-preview');
    Route::post('/preview-provisional-letter', 'provisionalLetterPreview')->name('preview-provisional-letter');
    Route::post('/preview-finalallocation-letter', 'finalLetterPreview')->name('preview-final-letter');
    Route::post('/send-receipt','sendReceiptEmail')->name('send.receipt.email');
});

Route::controller(AgentController::class)->group(function () {
    Route::get('/agents', 'agents')->name('agents');
    Route::get('/view_agent','viewApppliccations')->name('view-agent-details');
});

 Route::controller(ProductListController::class)->group(function () {
    Route::get('/all-products', 'allProducts')->name('all_pproducts');
    Route::get('/all-flats/{id}', 'availableFlatsonProducts')->name('available_flats');
});

});



 Route::get('/logout', function () {
    session()->flush();
    return redirect('/')->with('success', 'You have been successfully logged out.');
})->name('logout');


