<?php


use App\Http\Controllers\Admin\BlogCategoryController;
use App\Http\Controllers\Admin\BlogController;
use App\Http\Controllers\Admin\BranchController;
use App\Http\Controllers\Admin\BusinessModelController;
use App\Http\Controllers\Admin\CountryController;
use App\Http\Controllers\Admin\PackageController;
use App\Http\Controllers\Admin\PartnerController;
use App\Http\Controllers\Admin\ReviewController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\ContactManageController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\Admin\ProjectManageController;
use App\Http\Controllers\Admin\ServiceController;
use App\Http\Controllers\Admin\ServiceRequestController;
use App\Http\Controllers\Admin\StateController;
use App\Http\Controllers\Admin\UsersController;
use App\Http\Controllers\AdminDashboardController;
use App\Http\Controllers\BusinessTypeController;
use Illuminate\Support\Facades\Route;


Route::middleware(['auth'])->group(function () {


    // only admin 
    Route::middleware(['admin.only'])->group(function () {
        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/services', [ServiceController::class, 'index'])->name('services.index');
            Route::get('/services/create', [ServiceController::class, 'create'])->name('services.create');
            Route::post('/services', [ServiceController::class, 'store'])->name('services.store');
            Route::get('/services/{service}/edit', [ServiceController::class, 'edit'])->name('services.edit');
            Route::put('/services/{service}', [ServiceController::class, 'update'])->name('services.update');
            Route::delete('/services/{service}', [ServiceController::class, 'destroy'])->name('services.destroy');
            Route::post('/services/{service}/toggle-status', [ServiceController::class, 'toggleStatus'])->name('services.toggle-status');
            Route::get('/filter', [ServiceController::class, 'filterByCountry'])->name('services.filter');
        });



        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/packages', [PackageController::class, 'index'])->name('packages.index');
            Route::get('/packages/create', [PackageController::class, 'create'])->name('packages.create');
            Route::post('/packages', [PackageController::class, 'store'])->name('packages.store');
            Route::get('/packages/{package}/edit', [PackageController::class, 'edit'])->name('packages.edit');
            Route::put('/packages/{package}', [PackageController::class, 'update'])->name('packages.update');
            Route::delete('/packages/{package}', [PackageController::class, 'destroy'])->name('packages.destroy');
            Route::post('/packages/{package}/toggle-status', [PackageController::class, 'toggleStatus'])->name('packages.toggle-status');
            Route::post('/packages/{package}/toggle-featured', [PackageController::class, 'toggleFeatured'])->name('packages.toggle-featured');
        });

        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/business-types', [BusinessTypeController::class, 'index'])->name('business-types.index');
            Route::get('/business-types/create', [BusinessTypeController::class, 'create'])->name('business-types.create');
            Route::post('/business-types', [BusinessTypeController::class, 'store'])->name('business-types.store');
            Route::get('/business-types/{business_type}/edit', [BusinessTypeController::class, 'edit'])->name('business-types.edit');
            Route::put('/business-types/{business_type}', [BusinessTypeController::class, 'update'])->name('business-types.update');
            Route::delete('/business-types/{business_type}', [BusinessTypeController::class, 'destroy'])->name('business-types.destroy');
            Route::post('/business-types/{business_type}/toggle-status', [BusinessTypeController::class, 'toggleStatus'])->name('business-types.toggle-status');
        });

        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/business-models', [BusinessModelController::class, 'index'])->name('business-models.index');
            Route::get('/business-models/create', [BusinessModelController::class, 'create'])->name('business-models.create');
            Route::post('/business-models', [BusinessModelController::class, 'store'])->name('business-models.store');
            Route::get('/business-models/{business_model}/edit', [BusinessModelController::class, 'edit'])->name('business-models.edit');
            Route::put('/business-models/{business_model}', [BusinessModelController::class, 'update'])->name('business-models.update');
            Route::delete('/business-models/{business_model}', [BusinessModelController::class, 'destroy'])->name('business-models.destroy');
            Route::post('/business-models/{business_model}/toggle-status', [BusinessModelController::class, 'toggleStatus'])->name('business-models.toggle-status');
        });

        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/states', [StateController::class, 'index'])->name('states.index');
            Route::get('/states/create', [StateController::class, 'create'])->name('states.create');
            Route::post('/states', [StateController::class, 'store'])->name('states.store');
            Route::get('/states/{state}/edit', [StateController::class, 'edit'])->name('states.edit');
            Route::put('/states/{state}', [StateController::class, 'update'])->name('states.update');
            Route::delete('/states/{state}', [StateController::class, 'destroy'])->name('states.destroy');
            Route::post('/states/{state}/toggle-status', [StateController::class, 'toggleStatus'])->name('states.toggle-status');
        });


        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/settings', [SettingController::class, 'index'])->name('settings.index');
            Route::post('/settings', [SettingController::class, 'update'])->name('settings.update');
            Route::post('/settings/reset', [SettingController::class, 'reset'])->name('settings.reset');
            Route::delete('/settings/logo', [SettingController::class, 'deleteLogo'])->name('settings.delete-logo');
        });

        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::prefix('partners')->name('partners.')->group(function () {
                Route::get('/', [PartnerController::class, 'index'])->name('index');
                Route::get('/create', [PartnerController::class, 'create'])->name('create');
                Route::post('/', [PartnerController::class, 'store'])->name('store');
                Route::get('/{partner}/edit', [PartnerController::class, 'edit'])->name('edit');
                Route::put('/{partner}', [PartnerController::class, 'update'])->name('update');
                Route::delete('/{partner}', [PartnerController::class, 'destroy'])->name('destroy');
                Route::post('/{partner}/toggle-status', [PartnerController::class, 'toggleStatus'])->name('toggle-status');
                Route::post('/update-order', [PartnerController::class, 'updateOrder'])->name('update-order');
            });

        });
        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::prefix('reviews')->name('reviews.')->group(function () {
                Route::get('/', [ReviewController::class, 'index'])->name('index');
                Route::get('/create', [ReviewController::class, 'create'])->name('create');
                Route::post('/', [ReviewController::class, 'store'])->name('store');
                Route::get('/{review}/edit', [ReviewController::class, 'edit'])->name('edit');
                Route::put('/{review}', [ReviewController::class, 'update'])->name('update');
                Route::delete('/{review}', [ReviewController::class, 'destroy'])->name('destroy');
                Route::post('/{review}/approve', [ReviewController::class, 'approve'])->name('approve');
                Route::post('/{review}/feature', [ReviewController::class, 'feature'])->name('feature');
                Route::get('/pending', [ReviewController::class, 'pending'])->name('pending');
                Route::get('/featured', [ReviewController::class, 'featured'])->name('featured');
            });

        });
        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::prefix('countries')->name('countries.')->group(function () {
                Route::get('/', [CountryController::class, 'index'])->name('index');
                Route::get('/create', [CountryController::class, 'create'])->name('create');
                Route::post('/', [CountryController::class, 'store'])->name('store');
                Route::get('/{country}/edit', [CountryController::class, 'edit'])->name('edit');
                Route::put('/{country}', [CountryController::class, 'update'])->name('update');
                Route::delete('/{country}', [CountryController::class, 'destroy'])->name('destroy');
                Route::post('/{country}/toggle-status', [CountryController::class, 'toggleStatus'])->name('toggle-status');
                Route::post('/update-order', [CountryController::class, 'updateOrder'])->name('update-order');
            });

        });


        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/users', [UsersController::class, 'index'])->name('users.index');
            Route::get('/users/create', [UsersController::class, 'create'])->name('users.create');
            Route::post('/users', [UsersController::class, 'store'])->name('users.store');
            Route::get('/users/{user}/edit', [UsersController::class, 'edit'])->name('users.edit');
            Route::put('/users/{user}', [UsersController::class, 'update'])->name('users.update');
            Route::delete('/users/{user}', [UsersController::class, 'destroy'])->name('users.destroy');
        });
        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::prefix('branches')->name('branches.')->group(function () {
                Route::get('/', [BranchController::class, 'index'])->name('index');
                Route::get('/create', [BranchController::class, 'create'])->name('create');
                Route::post('/', [BranchController::class, 'store'])->name('store');
                Route::get('/{branch}/edit', [BranchController::class, 'edit'])->name('edit');
                Route::put('/{branch}', [BranchController::class, 'update'])->name('update');
                Route::delete('/{branch}', [BranchController::class, 'destroy'])->name('destroy');
            });
        });

    });






    // Routes accessible only to admin
    Route::middleware(['admin'])->group(function () {

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

        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::prefix('blog')->name('blog.')->group(function () {
                Route::get('/', [BlogController::class, 'index'])->name('index');
                Route::get('/create', [BlogController::class, 'create'])->name('create');
                Route::post('/', [BlogController::class, 'store'])->name('store');
                Route::get('/{blog}/edit', [BlogController::class, 'edit'])->name('edit');
                Route::put('/{blog}', [BlogController::class, 'update'])->name('update');
                Route::delete('/{blog}', [BlogController::class, 'destroy'])->name('destroy');
                Route::post('/{blog}/toggle-status', [BlogController::class, 'toggleStatus'])->name('toggle-status');
                Route::post('/{blog}/toggle-featured', [BlogController::class, 'toggleFeatured'])->name('toggle-featured');

                Route::prefix('categories')->name('categories.')->group(function () {
                    Route::get('/', [BlogCategoryController::class, 'index'])->name('index');
                    Route::post('/', [BlogCategoryController::class, 'store'])->name('store');
                    Route::put('/{category}', [BlogCategoryController::class, 'update'])->name('update');
                    Route::delete('/{category}', [BlogCategoryController::class, 'destroy'])->name('destroy');
                    Route::post('/{category}/toggle-status', [BlogCategoryController::class, 'toggleStatus'])->name('toggle-status');
                });
            });
        });


        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/contacts', [ContactManageController::class, 'index'])->name('contacts.index');
            Route::get('/contacts/{contact}', [ContactManageController::class, 'show'])->name('contacts.show');
            Route::put('/contacts/{contact}/status', [ContactManageController::class, 'updateStatus'])->name('contacts.update-status');
            Route::delete('/contacts/{contact}', [ContactManageController::class, 'destroy'])->name('contacts.destroy');
            Route::post('/contacts/bulk-action', [ContactManageController::class, 'bulkAction'])->name('contacts.bulk-action');
            Route::get('/contacts/statistics', [ContactManageController::class, 'getStatistics'])->name('contacts.statistics');
        });


        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/service-requests', [ServiceRequestController::class, 'index'])->name('service-requests.index');
            Route::get('/service-requests/{serviceRequest}', [ServiceRequestController::class, 'show'])->name('service-requests.show');
            Route::get('/service-requests/{serviceRequest}/edit', [ServiceRequestController::class, 'edit'])->name('service-requests.edit');
            Route::put('/service-requests/{serviceRequest}', [ServiceRequestController::class, 'update'])->name('service-requests.update');
            Route::delete('/service-requests/{serviceRequest}', [ServiceRequestController::class, 'destroy'])->name('service-requests.destroy');
            Route::post('/service-requests/{serviceRequest}/update-status', [ServiceRequestController::class, 'updateStatus'])->name('service-requests.update-status');
        });


        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/start-project/{id}', [ProjectManageController::class, 'index'])->name('start-Project.index');
            Route::post('/start-project/submit/{id}', [ProjectManageController::class, 'submit_project'])->name('start-Project.submit');
            Route::get('/all-project', [ProjectManageController::class, 'allProject'])->name('Project.allProject.index');
            Route::get('/show-project/{id}', [ProjectManageController::class, 'show'])->name('project.show.index');
            Route::get('/upload-data-project/{id}', [ProjectManageController::class, 'upload_data'])->name('project.upload_data');
            Route::post('/admin/projects/{id}/store-service-document', [ProjectManageController::class, 'storeServiceDocument']) ->name('projects.store-service-document');
            Route::delete('/admin/projects/{id}/delete-service-document', [ProjectManageController::class, 'deleteServiceDocument'])->name('projects.delete-service-document');

            Route::patch('/admin/projects/{id}/update-status', [ProjectManageController::class, 'updateStatus'])->name('projects.update-status');
            Route::post('/admin/projects/{id}/update-discount', [ProjectManageController::class, 'discount'])->name('projects.discount');
            Route::patch('/admin/projects/{id}/update-service-status', [ProjectManageController::class, 'updateServiceStatus'])->name('projects.update-service-status');
            Route::get('/create-payment/{id}', [ProjectManageController::class, 'create_payment'])->name('payments.create');
            Route::post('/payments', [PaymentController::class, 'payment_store'])->name('payments.store');

            Route::get('/invoice', [PaymentController::class, 'invoice'])->name('invoice.index');
            Route::get('/invoices', [PaymentController::class, 'invoice'])->name('payments.invoice');
            Route::get('/payments/{id}/view', [PaymentController::class, 'view'])->name('payments.view');
            Route::get('/payments/{id}/download', [PaymentController::class, 'download'])->name('payments.download');
            Route::get('/payments/{id}/edit', [PaymentController::class, 'edit'])->name('payments.edit');
            Route::delete('/payments/{id}', [PaymentController::class, 'destroy'])->name('payments.destroy');
        });

        Route::prefix('admin/panel')->name('admin.')->group(function () {
            Route::get('/transection', [PaymentController::class, 'transection'])->name('payments.transection');
            Route::get('/transection/{id}/show', [PaymentController::class, 'transection_show'])->name('payments.transection_show');
            Route::put('/transection/{id}/status', [PaymentController::class, 'transection_update'])->name('payments.transection_update');
        });
    });
});