<?php

declare(strict_types=1);

use App\Http\Controllers\ApiLogController;
use App\Http\Controllers\QueueProcessLogController;
use App\Http\Controllers\AssetController;
use App\Http\Controllers\AttributeController;
use App\Http\Controllers\AuditController;
use App\Http\Controllers\AutoGrabNotificationController;
use App\Http\Controllers\AutoImagingNotificationController;
use App\Http\Controllers\AutosOnShowNotificationController;
use App\Http\Controllers\AutoTraderHubNotificationController;
use App\Http\Controllers\BillingController;
use App\Http\Controllers\BlogImportController;
use App\Http\Controllers\WordPressBlogImportController;
use App\Http\Controllers\CarConfiguratorController;
use App\Http\Controllers\ConfiguratorExtraController;
use App\Http\Controllers\ConfiguratorPackageController;
use App\Http\Controllers\EnquiryController;
use App\Http\Controllers\ExportMapController;
use App\Http\Controllers\ElementController;
use App\Http\Controllers\FeedController;
use App\Http\Controllers\ChecklistController;
use App\Http\Controllers\ColourMapController;
use App\Http\Controllers\CurrencyController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\DealershipController;
use App\Http\Controllers\FilterFeatureController;
use App\Http\Controllers\FranchiseController;
use App\Http\Controllers\GlobalContentController;
use App\Http\Controllers\ImportConditionController;
use App\Http\Controllers\ImportMapController;
use App\Http\Controllers\ImportMapTaxonomyController;
use App\Http\Controllers\InvoiceController;
use App\Http\Controllers\LeaseImportMakeController;
use App\Http\Controllers\LeaseImportModelController;
use App\Http\Controllers\LeaseVehicleController;
use App\Http\Controllers\MediaController as AppMediaController;
use App\Http\Controllers\NewCarBulkUpdateController;
use App\Http\Controllers\NewCarController;
use App\Http\Controllers\OfferFinanceFieldConfigController;
use App\Http\Controllers\OfferTypeController;
use App\Http\Controllers\OptionListController;
use App\Http\Controllers\OutAndAboutController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\PhyronController;
use App\Http\Controllers\PropertyCategoryController;
use App\Http\Controllers\FranchiseSitemapController;
use App\Http\Controllers\PropertyCategorySitemapController;
use App\Http\Controllers\PropertyController;
use App\Http\Controllers\SitemapController;
use App\Http\Controllers\ReleaseNoteController;
use App\Http\Controllers\ReportController;
use App\Http\Controllers\SearchTermReportController;
use App\Http\Controllers\ReservationController;
use App\Http\Controllers\ReservationPriceController;
use App\Http\Controllers\ReservationStatusController;
use App\Http\Controllers\SalesChannelController;
use App\Http\Controllers\SalesForceNotificationController;
use App\Http\Controllers\SearchController;
use App\Http\Controllers\SearchFacetController;
use App\Http\Controllers\Seo404Controller;
use App\Http\Controllers\SeoController;
use App\Http\Controllers\SeoDataController;
use App\Http\Controllers\SeoDefaultController;
use App\Http\Controllers\SeoHeadingController;
use App\Http\Controllers\SeoRedirectController;
use App\Http\Controllers\ShortcodeController;
use App\Http\Controllers\SiteDomainController;
use App\Http\Controllers\ReplacementController;
use App\Http\Controllers\TenantTaxonomyController;
use App\Http\Controllers\ValuationController;
use App\Http\Controllers\VehicleOfferController;
use App\Http\Controllers\Api\ExportMapApiController;
use App\Http\Controllers\Api\VehicleController as ApiVehicleController;
use App\Http\Middleware\ApiAuthenticatedRequest;
use App\Http\Middleware\InitializeTenancyByDomainInRequest;
use App\Http\Middleware\InitializeTenancyBySiteInRequest;
use App\Modules\CatalogOffers\Http\Controllers\CatalogOfferController;
use App\Modules\ServiceBooking\Http\Controllers\BookingController;
use App\Modules\ServiceBooking\Http\Controllers\ServiceAvailabilityController;
use App\Modules\ServiceBooking\Http\Controllers\ServiceCalendarController;
use App\Modules\ServiceBooking\Http\Controllers\ServiceDeliveryController;
use App\Modules\ServiceBooking\Http\Controllers\ServicePackageController;
use App\Modules\Valuation\Http\Controllers\ValuationAdjustmentController;
use App\Modules\VehicleLabels\Http\Controllers\LabelController;
use App\Modules\VehicleTrims\Http\Controllers\VehicleTrimController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TemplateController;
use Mtc\Notifications\Http\Controllers\NotificationController;
use Stancl\Tenancy\Middleware\InitializeTenancyByPath;
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
use App\Master\Http\Controllers\UploadProfilePhotoController;
use App\Http\Controllers\BodyStyleController;
use App\Http\Controllers\BulkDeleteController;
use App\Http\Controllers\CapIdCacheController;
use App\Http\Controllers\DrivetrainController;
use App\Http\Controllers\FuelTypeController;
use App\Http\Controllers\MakeController;
use App\Http\Controllers\MeilisearchSettingsController;
use App\Http\Controllers\ModelController;
use App\Http\Controllers\PinnedItemController;
use App\Http\Controllers\SantanderProductController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\SiteUserController;
use App\Http\Controllers\TransmissionController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\VehicleBulkUpdateController;
use App\Http\Controllers\VehicleController;
use Illuminate\Routing\Router;

/*
|--------------------------------------------------------------------------
| Tenant Routes
|--------------------------------------------------------------------------
|
| Here you can register the tenant routes for your application.
| These routes are loaded by the TenantRouteServiceProvider.
|
| Feel free to customize them however you want. Good luck!
|
*/

Route::prefix('api')
    ->as('tenant.')
    ->middleware([
        'api',
        InitializeTenancyByRequestData::class,
        'auth:sanctum'
    ])
    ->group(function (Router $router) {
        $router->get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
        $router->post('/dashboard/graph', [DashboardController::class, 'graph']);
        $router->get('/dashboard/content', [DashboardController::class, 'content'])->name('content-dashboard');
        $router->get('/dashboard/crm', [DashboardController::class, 'crm'])->name('crm-dashboard');
        $router->get('/dashboard/taxonomies', [DashboardController::class, 'taxonomies'])->name('taxonomy-dashboard');
        $router->get('/bulk-import-log/{type}', [DashboardController::class, 'bulkImportLog'])->name('bulk-import-log');
        $router->post('/bulk-import-log/download-file/{log}', [DashboardController::class, 'bulkImportLogFile'])->name('download-import-log-file');
        $router->get('/sidebar', [DashboardController::class, 'sidebar'])->name('sidebar');
        $router->post('/search', [SearchController::class, 'index'])->name('search');
        $router->post('/search/elements', [SearchController::class, 'elements'])->name('search.content');
        $router->post('/search/vehicles', [SearchController::class, 'vehicles'])->name('search.vehicles');
        $router->get('/search/{type}/filters', [SearchController::class, 'getFilters']);


        $router->post('site-unmapped-taxonomies', [TenantTaxonomyController::class, 'index']);
        $router->put('site-unmapped-taxonomies/{map}', [TenantTaxonomyController::class, 'update']);

        $router->get('/audit', [AuditController::class, 'index'])->name('audit.index');
        $router->get('/audit/setting', [AuditController::class, 'forSetting'])->name('audit.for-setting');
        $router->get('/audit/auditable', [AuditController::class, 'forAuditable'])->name('audit.for-auditable');
        $router->get('/audit/{audit}', [AuditController::class, 'show'])->name('audit.show');

        $router->get('/data/get-types', [OptionListController::class, 'getTypes'])->name('data-types');
        $router->get('/data/dealership-email-fields', [OptionListController::class, 'getDealershipEmailFields'])->name('dealership-email-fields');
        $router->get('/data/{type}', [OptionListController::class, 'index'])->name('data-list');

        // notifications
        $router->post('/notification-centre', [NotificationController::class, 'index'])->name('notifications.view');
        $router->put('/notification-centre/mark-read', [NotificationController::class, 'markRead'])->name('notifications.mark-read');
        $router->put('/notification-centre/mark-unread', [NotificationController::class, 'markUnread'])->name('notifications.mark-unread');
        $router->put('/notification-centre/delete', [NotificationController::class, 'destroy'])->name('notifications.delete');

        // users
        $router->get('/user/get-dashboard/{section}', [DashboardController::class, 'getDashboardWidgets'])->name('user.get-dashboard-widgets');
        $router->put('/user/set-dashboard/{section}', [DashboardController::class, 'setDashboardWidgets'])->name('user.set-dashboard-widgets');
        $router->get('/users', [UserController::class, 'siteUsers'])->name('users.index');
        $router->post('/user/profile-photo', [UploadProfilePhotoController::class, 'update'])
            ->name('users.profile');

        // pinned items
        $router->get('pinned-items', [PinnedItemController::class, 'show'])->name('pinned-items.index');
        $router->post('pinned-items', [PinnedItemController::class, 'store'])->name('pinned-items.store');
        $router->delete('pinned-items/{pinned_item_id}', [PinnedItemController::class, 'destroy'])->name('pinned-items.destroy');

        $router->group([
            'prefix' => 'checklists/',
            'as' => 'checklists.',
        ], function ($router) {
            $router->post('domain-check/{domain}', [ChecklistController::class, 'checkDomain'])->name('domain');
            $router->post('mail-check', [ChecklistController::class, 'checkMail'])->name('mail');
        });

        $router->group([
            'prefix' => 'settings/seo/',
            'as' => 'seo_settings.',
        ], function (Router $router) {
            $router->post('defaults', [SeoDefaultController::class, 'bulkUpdate']);
            $router->apiResource('defaults', SeoDefaultController::class)->only(['index', 'update']);
            $router->post('data/export', [SeoDataController::class, 'export'])->name('data.export');
            $router->post('data/import', [SeoDataController::class, 'import'])->name('data.import');
            $router->delete('data/bulk-delete', [SeoDataController::class, 'bulkDestroy'])->name('data.bulk-delete');
            $router->apiResource('data', SeoDataController::class);
            $router->post('404s/export', [Seo404Controller::class, 'export'])->name('404s.export');
            $router->get('404s', [Seo404Controller::class, 'index'])->name('404s.index');
            $router->post('redirects/export', [SeoRedirectController::class, 'export'])->name('redirects.export');
            $router->post('redirects/import', [SeoRedirectController::class, 'import'])->name('redirects.import');
            $router->post('redirects/verify', [SeoRedirectController::class, 'verify'])->name('redirects.verify');
            $router->delete('redirects/bulk-delete', [SeoRedirectController::class, 'bulkDestroy'])->name('redirects.bulk-delete');
            $router->apiResource('redirects', SeoRedirectController::class);
            $router->post('headings/export', [SeoHeadingController::class, 'export'])->name('headings.export');
            $router->post('headings/import', [SeoHeadingController::class, 'import'])->name('headings.import');
            $router->apiResource('headings', SeoHeadingController::class)->except(['show']);

            $router->middleware([
                'enabled-feature:search-facets',
                'permission:edit-seo'
            ])
                ->group(function (Router $router) {
                    $router->get('facets/available', [SearchFacetController::class, 'available'])->name('facets.available');
                    $router->post('facets/reorder', [SearchFacetController::class, 'reorder'])->name('facets.reorder');
                    $router->apiResource('facets', SearchFacetController::class)->except(['show']);
                });
        });

        $router->post('blog/import', [BlogImportController::class, 'import'])->name('blog.import');
        $router->get('blog/import/templates/{template}/elements', [BlogImportController::class, 'templateElements'])
            ->name('blog.import.template-elements');

        $router->group([
            'prefix' => 'service-bookings',
            'as' => 'service-booking.',
        ], function (Router $router) {
            $router->post('calendar', [ServiceCalendarController::class, 'index'])->name('calendar');
            $router->apiResource('bookings', BookingController::class)->only(['index', 'show', 'update']);
            $router->put('packages/order', [ServicePackageController::class, 'saveOrder']);
            $router->apiResource('packages', ServicePackageController::class);
            $router->apiResource('availability', ServiceAvailabilityController::class)->only(['index', 'show', 'update', 'delete']);
            $router->apiResource('delivery', ServiceDeliveryController::class);
        });

        $router->post('/seo/check-slug', [SeoController::class, 'checkSlug'])->name('seo.check-slug');

        $router->post('/upload-asset', [AssetController::class, 'store']);
        $router->delete('/remove-asset', [AssetController::class, 'destroy']);

        $router->get('sales-channels/', [SalesChannelController::class, 'index'])->name('sales-channels.index');
        $router->get('sales-channels/{channel}', [SalesChannelController::class, 'show'])->name('sales-channels.show');
        $router->put('sales-channels/{channel}', [SalesChannelController::class, 'update'])->name('sales-channels.update');
        $router->get('sales-channels/{channel}/dealerships', [SalesChannelController::class, 'dealerships'])->name('sales-channels.dealerships');
        $router->get('sales-channels/{channel}/location/{locationId}', [SalesChannelController::class, 'locationStock'])->name('sales-channels.location-stock');
        $router->delete('sales-channels/{channel}/location/{locationId}/vehicle/{stockId}', [SalesChannelController::class, 'removeUnmatchedVehicle'])->name('sales-channels.remove-unmatched-vehicle');
        $router->patch('sales-channels/{channel}/publish-advert', [SalesChannelController::class, 'updatePublishAdvert'])->name('sales-channels.publish-advert');
        $router->patch('sales-channels/{channel}/publish-profile', [SalesChannelController::class, 'updatePublishProfile'])->name('sales-channels.publish-profile');

        // settings & billing
        $router->apiResource('billing/invoices', InvoiceController::class)->only(['index', 'show']);

        $router->get('settings/leasing/makes', [LeaseImportMakeController::class, 'index'])->name('leasing.makes.index');
        $router->get('settings/leasing/make/{make:id}', [LeaseImportMakeController::class, 'show'])->name('leasing.makes.show');
        $router->put('settings/leasing/make/{make:id}', [LeaseImportMakeController::class, 'update'])->name('leasing.makes.update');
        $router->post('settings/leasing/makes', [LeaseImportMakeController::class, 'updateBulk'])->name('leasing.makes.update-bulk');
        $router->get('settings/leasing/models/{make_id}', [LeaseImportModelController::class, 'index'])->name('leasing.models.index');
        $router->post('settings/leasing/models/{make_id}', [LeaseImportModelController::class, 'updateBulk'])->name('leasing.models.update-bulk');

        $router->get('settings/import-maps/get/{model}', [ImportMapController::class, 'getForModel']);
        $router->post('settings/import-maps/{importMap}/upload', [ImportMapController::class, 'upload']);
        $router->post('settings/import-maps/{importMap}/download/{file}', [ImportMapController::class, 'download'])->where('file', '.*');
        $router->get('settings/import-maps/{importMap}/taxonomy-maps', [ImportMapTaxonomyController::class, 'index']);
        $router->post('settings/import-maps/{importMap}/taxonomy-maps', [ImportMapTaxonomyController::class, 'store']);
        $router->put('settings/import-maps/{importMap}/taxonomy-maps/{taxonomyMap}', [ImportMapTaxonomyController::class, 'update']);
        $router->apiResource('settings/import-maps', ImportMapController::class);
        $router->post('settings/import-conditions/get-rules', [ImportConditionController::class, 'getRuleOptions'])
            ->name('import-conditions.get-rules');
        $router->get('settings/import-conditions/get-providers', [ImportConditionController::class, 'getProviders'])
            ->name('import-conditions.get-providers');;
        $router->apiResource('settings/import-conditions', ImportConditionController::class);
        $router->apiResource('settings/reservation-prices', ReservationPriceController::class);

        $router->get('meilisearch/typo-tolerance', [MeilisearchSettingsController::class, 'getTypoTolerance']);
        $router->put('meilisearch/typo-tolerance', [MeilisearchSettingsController::class, 'updateTypoTolerance']);
        $router->get('meilisearch/stop-words', [MeilisearchSettingsController::class, 'getStopWords']);
        $router->put('meilisearch/stop-words', [MeilisearchSettingsController::class, 'updateStopWords']);
        $router->get('meilisearch/ranking-rules', [MeilisearchSettingsController::class, 'getRankingRules']);
        $router->put('meilisearch/ranking-rules', [MeilisearchSettingsController::class, 'updateRankingRules']);
        $router->get(
            'meilisearch/searchable-attributes',
            [MeilisearchSettingsController::class, 'getSearchableAttributes']
        );
        $router->put(
            'meilisearch/searchable-attributes',
            [MeilisearchSettingsController::class, 'updateSearchableAttributes']
        );
        $router->get('meilisearch/faceting', [MeilisearchSettingsController::class, 'getFaceting']);
        $router->put('meilisearch/faceting', [MeilisearchSettingsController::class, 'updateFaceting']);
        $router->post('meilisearch/search', [MeilisearchSettingsController::class, 'search']);

        $router->delete('cap-id-cache/clear', [CapIdCacheController::class, 'clear']);
        $router->apiResource('cap-id-cache', CapIdCacheController::class)->only(['index', 'destroy']);

        $router->get('settings/export-maps/get/{model}', [ExportMapController::class, 'getForModel']);
        $router->get('settings/export-maps/{exportMap}/download', [ExportMapController::class, 'download'])
            ->name('export-maps.download');
        $router->apiResource('settings/export-maps', ExportMapController::class);

        $router->get('settings/billing', [BillingController::class, 'index'])
            ->name('settings.billing.index');
        $router->put('settings/billing/subscription', [BillingController::class, 'updateSubscription'])
            ->name('settings.billing.update-subscription');
        $router->put('settings/billing/details', [BillingController::class, 'updateDetails'])
            ->name('settings.billing.update-details');
        $router->put('settings/domains/{domain}/make-primary', [SiteDomainController::class, 'makePrimary']);
        $router->put('settings/domains/{domain}/force', [SiteDomainController::class, 'force']);
        $router->apiResource('settings/domains', SiteDomainController::class)->only(['index', 'store', 'destroy']);
        $router->get('settings/site-users', [SiteUserController::class, 'show'])
            ->name('settings.site-users.show');
        $router->post('settings/site-users', [SiteUserController::class, 'store'])
            ->name('settings.site-users.store');
        $router->put('settings/site-users', [SiteUserController::class, 'update'])
            ->name('settings.site-users.update');
        $router->delete('settings/site-users', [SiteUserController::class, 'destroy'])
            ->name('settings.site-users.destroy');
        $router->post('settings/site-users/resend', [SiteUserController::class, 'resendInvite'])
            ->name('settings.site-users.resend');
        $router->get('settings/replacements', [ReplacementController::class, 'show'])
            ->name('settings.replacements.show');
        $router->get('settings/replacements-types', [ReplacementController::class, 'showTypes'])
            ->name('settings.replacements.show-types');
        $router->post('settings/replacements', [ReplacementController::class, 'store'])
            ->name('settings.replacements.store');
        $router->put('settings/replacements/{replacement}', [ReplacementController::class, 'update'])
            ->name('settings.replacements.update');
        $router->delete('settings/replacements/{replacement}', [ReplacementController::class, 'destroy'])
            ->name('settings.replacements.destroy');
        $router->get('settings/santander-products', [SantanderProductController::class, 'index']);
        $router->post('settings/verify', [SettingController::class, 'verify']);
        $router->post('settings/trigger-action', [SettingController::class, 'triggerAction']);
        $router->get('settings', [SettingController::class, 'index'])
            ->name('settings.index');
        $router->get('settings/search', [SettingController::class, 'search']);
        $router->get('settings/{tab}', [SettingController::class, 'show'])
            ->name('settings.show');
        $router->put('settings/{section}', [SettingController::class, 'update'])
            ->name('settings.update');
        $router->post('settings', [SettingController::class, 'store'])
            ->name('settings.store');

        // taxonomies
        $router->resource('vehicle-taxonomies/makes', MakeController::class)->only(['index', 'show']);
        $router->get('vehicle-taxonomies/makes/{make_id}/models', [ModelController::class, 'index'])
            ->name('make-models');
        $router->get('vehicle-taxonomies/models/{model}', [ModelController::class, 'show'])->name('models');
        $router->resource('vehicle-taxonomies/drivetrains', DrivetrainController::class)->only(['index', 'show']);
        $router->resource('vehicle-taxonomies/transmissions', TransmissionController::class)->only([
            'index',
            'show'
        ]);
        $router->resource('vehicle-taxonomies/fuel-types', FuelTypeController::class)->only(['index', 'show']);
        $router->resource('vehicle-taxonomies/body-styles', BodyStyleController::class)->only(['index', 'show']);

        $router->resource('currencies', CurrencyController::class)->only(['index']);

        $router->apiResource('{model}/attributes', AttributeController::class);

        // vehicles
        $router->get('vehicles/featured', [VehicleController::class, 'getFeatured'])->name('vehicles.get-featured');
        $router->get('vehicles/warnings', [VehicleController::class, 'getWarnings'])->name('vehicles.get-warnings');
        $router->put('vehicles/featured', [VehicleController::class, 'setFeatured'])
            ->name('vehicles.set-featured');

        // Vehicle bulk update
        $router->middleware(['permission:edit-vehicles'])->group(function ($router) {
            $router->get('vehicles/bulk-update/fields', [VehicleBulkUpdateController::class, 'getFields'])
                ->name('vehicles.bulk-update.fields');
            $router->post('vehicles/bulk-update/vehicle-data', [VehicleBulkUpdateController::class, 'getVehicleData'])
                ->name('vehicles.bulk-update.vehicle-data');
            $router->post('vehicles/bulk-update', [VehicleBulkUpdateController::class, 'update'])
                ->name('vehicles.bulk-update');
            $router->post('vehicles/bulk-update/delete-finance', [VehicleBulkUpdateController::class, 'deleteFinanceExamples'])
                ->name('vehicles.bulk-update.delete-finance');
            $router->post('vehicles/bulk-update/request-finance', [VehicleBulkUpdateController::class, 'requestFinanceQuotes'])
                ->name('vehicles.bulk-update.request-finance');
        });

        $router->group([
            'prefix' => 'vehicles/{vehicle}',
            'as' => 'vehicles.'
        ], function () use ($router) {
            $router->post('get-finance', [VehicleController::class, 'getFinance'])->name('get-finance');
            $router->post('get-cap-id', [VehicleController::class, 'getCapId'])->name('get-cap-id');
            $router->post('get-ai-description', [VehicleController::class, 'getAIDescription'])
                ->name('get-ai-description');
            $router->post('get-stock-sync-log', [VehicleController::class, 'getStockSyncLogRecords'])
                ->name('get-stock-sync-log');
            $router->post('get-spec', [VehicleController::class, 'getSpec'])->name('get-spec');
            $router->post('copy', [VehicleController::class, 'copy'])->name('copy');
            $router->post('restore', [VehicleController::class, 'restore'])->name('restore');
            $router->post('set-status', [VehicleController::class, 'updateStatus'])->name('set-status');
            $router->post('get-images', [VehicleController::class, 'getImages'])->name('get-images');
            $router->post('recommended-images-order', [VehicleController::class, 'getRecommendedImagesOrder'])
                ->name('recommended-images-order');
        });

        $router->post('vehicles/export/{exportMap?}', [VehicleController::class, 'export'])
            ->name('vehicles.export');
        $router->post('vehicles/import/{type?}', [VehicleController::class, 'import'])
            ->name('vehicles.import');

        // Bulk delete specified models
        $router->delete('bulk-delete', [BulkDeleteController::class, 'handle'])->name('bulk-delete');

        $router->post('vehicle-lookup', [VehicleController::class, 'lookup']);
        $router->post('vehicles/{vehicle}/media-recrop', [VehicleController::class, 'reCropMedia'])->name('vehicles.media-recrop');
        $router->post('vehicles/{vehicle}/remove-auto-trader', [VehicleController::class, 'removeFromAutoTrader'])->name('vehicles.remove-from-auto-trader');
        $router->post('vehicles/{vehicle}/refresh-auto-trader-status', [VehicleController::class, 'refreshAutoTraderStatus'])->name('vehicles.refresh-auto-trader-status');
        $router->get('vehicle-search', [VehicleController::class, 'index']);
        $router->post('vehicle-search', [VehicleController::class, 'index']);
        $router->put('vehicle-search', [VehicleController::class, 'saveOrder'])
            ->name('vehicles.save-order');
        $router->any('vehicle-print', [VehicleController::class, 'print']);
        $router->apiResource('vehicles', VehicleController::class);

        // Vehicle Subscriptions
        $router->group(['middleware' => 'enabled-feature:vehicle-subscriptions'], function (Router $router) {
            $router->get('vehicle-subscriptions', [\App\Http\Controllers\VehicleSubscriptionController::class, 'index'])
                ->name('vehicle-subscriptions.index');
            $router->get('vehicle-subscriptions/grouped-by-vehicle', [\App\Http\Controllers\VehicleSubscriptionController::class, 'groupedByVehicle'])
                ->name('vehicle-subscriptions.grouped-by-vehicle');
            $router->get('vehicle-subscriptions/stats', [\App\Http\Controllers\VehicleSubscriptionController::class, 'stats'])
                ->name('vehicle-subscriptions.stats');
            $router->get('vehicle-subscriptions/event-types', [\App\Http\Controllers\VehicleSubscriptionController::class, 'eventTypes'])
                ->name('vehicle-subscriptions.event-types');
            $router->get('vehicles/{vehicle}/subscriptions', [\App\Http\Controllers\VehicleSubscriptionController::class, 'forVehicle'])
                ->name('vehicle-subscriptions.for-vehicle');
            $router->delete('vehicle-subscriptions/{subscription}', [\App\Http\Controllers\VehicleSubscriptionController::class, 'destroy'])
                ->name('vehicle-subscriptions.destroy');
        });

        $router->apiResource('shortcodes', ShortcodeController::class);

        $router->get('franchises/{franchise}/usage', [FranchiseController::class, 'usage'])->name('franchise.usage');
        $router->post('franchises/{franchise}/copy', [FranchiseController::class, 'copy'])->name('franchise.copy');
        $router->apiResource('franchises', FranchiseController::class);
        $router->post('valuation-search', [ValuationController::class, 'index']);
        $router->get('valuations/{valuation}/future-value', [ValuationController::class, 'futureValue']);
        $router->apiResource('valuations', ValuationController::class)->only(['index', 'store', 'show']);
        $router->apiResource('offer-types', OfferTypeController::class);
        $router->apiResource('offer/finance-fields', OfferFinanceFieldConfigController::class)
            ->parameter('finance-fields', 'financeField');
        $router->apiResource('valuation-adjustments', ValuationAdjustmentController::class)->middleware('enabled-feature:valuation_adjustments');

        $router->get('content/global-elements/get-for-element/{element}', [GlobalContentController::class, 'forElement'])->name('global-content.for-element');
        $router->get('content/templates/{template}/usage', [TemplateController::class, 'usage'])->name('templates.usage');
        $router->get('content/templates/{template}/sync-all-usage', [TemplateController::class, 'syncUsage'])->name('templates.sync-usage');

        $router->get('content/elements/{element}/sync-all-usage', [ElementController::class, 'syncUsage'])->name('elements.sync-usage');
        $router->any('content-pages', [PageController::class, 'index']);
        $router->get('/content/media-stats', (new AppMediaController())->getStats(...))->name('media-stats');

        // offers
        $router->post('vehicle-offers/{vehicleOffer}/sync-template-fields', [VehicleOfferController::class, 'syncWithTemplate'])
            ->name('vehicle-offers.sync-template');
        $router->post('vehicle-offers/{vehicleOffer}/restore', [VehicleOfferController::class, 'restore']);
        $router->post('vehicle-offers/{vehicleOffer}/copy', [VehicleOfferController::class, 'copy'])
            ->name('vehicle-offers.copy');
        $router->post('vehicle-offers/{vehicleOffer}/restore-version/{version}', [VehicleOfferController::class, 'restoreVersion'])
            ->name('vehicle-offers.restore-version');
        $router->post('vehicle-offers/export', [VehicleOfferController::class, 'export'])
            ->name('vehicle-offers.export');
        $router->post('vehicle-offers/{vehicleOffer}/get-ai-description', [VehicleOfferController::class, 'getAIDescription'])
            ->name('vehicle-offers.get-ai-description');
        $router->post('vehicle-offers/import', [VehicleOfferController::class, 'import'])
            ->name('vehicle-offers.import');
        $router->get('vehicle-offers/featured', [VehicleOfferController::class, 'getFeatured'])
            ->name('vehicle-offers.get-featured');
        $router->put('vehicle-offers/featured', [VehicleOfferController::class, 'setFeatured'])
            ->name('vehicle-offers.set-featured');
        $router->apiResource('vehicle-offers', VehicleOfferController::class);
        $router->get('vehicle-offer-search', [VehicleOfferController::class, 'index']);
        $router->post('vehicle-offer-search', [VehicleOfferController::class, 'index']);
        $router->put('vehicle-offer-search', [VehicleOfferController::class, 'saveOrder'])
            ->name('vehicle-offers.save-order');

        // lease vehicles
        $router->any('lease-vehicles', [LeaseVehicleController::class, 'index'])->name('lease-vehicles.list');
        $router->post('lease-vehicles-bulk-update-featured', [LeaseVehicleController::class, 'update'])->name('lease-vehicles.update');

        // New car bulk update
        $router->middleware(['permission:edit-new-vehicles'])
            ->prefix('new-cars/')
            ->as('new-cars.bulk-update.')
            ->group(function ($router) {
            $router->get('bulk-update/fields', [NewCarBulkUpdateController::class, 'getFields'])->name('fields');
            $router->post('bulk-update/new-car-data', [NewCarBulkUpdateController::class, 'getNewCarData'])->name('new-car-data');
            $router->post('bulk-update', [NewCarBulkUpdateController::class, 'update'])->name('bulk-update');
            $router->post('bulk-update/delete-finance', [NewCarBulkUpdateController::class, 'deleteFinanceExamples'])->name('delete-finance');
        });

        // new cars
        $router->post('new-cars/{newCar}/sync-template-fields', [NewCarController::class, 'syncWithTemplate'])
            ->name('new-cars.sync-template');
        $router->post('new-cars/{newCar}/restore', [NewCarController::class, 'restore'])->name('new-cars.restore');
        $router->post('new-cars/{newCar}/copy', [NewCarController::class, 'copy'])->name('new-cars.copy');
        $router->post('new-cars/{newCar}/restore-version/{version}', [NewCarController::class, 'restoreVersion'])
            ->name('new-cars.restore-version');
        $router->apiResource('new-cars', NewCarController::class);
        $router->get('new-car-search', [NewCarController::class, 'index']);
        $router->post('new-car-search', [NewCarController::class, 'index']);
        $router->put('new-car-search', [NewCarController::class, 'saveOrder'])
            ->name('new-cars.save-order');


        $router->apiResource('car-configurator-packages', ConfiguratorPackageController::class);
        $router->apiResource('car-configurator-extras', ConfiguratorExtraController::class);
        $router->post('car-configurator/{carConfigurator}/get-media', [CarConfiguratorController::class, 'getMedia'])->name('car-configurator.get-media');
        $router->post('car-configurator/{carConfigurator}/save-media', [CarConfiguratorController::class, 'saveMedia'])->name('car-configurator.save-media');
        $router->post('car-configurator/{carConfigurator}/import-images', [CarConfiguratorController::class, 'importMedia'])->name('car-configurator.import-media');
        $router->post('car-configurator-search', [CarConfiguratorController::class, 'index'])->name('car-configurator.search');
        $router->apiResource('car-configurator', CarConfiguratorController::class);

        // dealerships
        $router->post('dealerships/{dealership}/copy', [DealershipController::class, 'copy'])->name('dealerships.copy');
        $router->post('dealerships/{dealership}/sync-template-fields', [DealershipController::class, 'syncWithTemplate'])
            ->name('dealerships.sync-template');
        $router->get('dealership-search', [DealershipController::class, 'index']);
        $router->post('dealership-search', [DealershipController::class, 'index']);
        $router->put('dealership-search', [DealershipController::class, 'saveOrder'])->name('dealerships.save-order');
        $router->apiResource('dealerships', DealershipController::class);


        $router->get('filter-features/search', [FilterFeatureController::class, 'search'])->name('filter-features.search');
        $router->apiResource('filter-features', FilterFeatureController::class);

        $router->group(['middleware' => 'enabled-feature:manage-standard-equipment'], function (Router $router) {
            $router->get('standard-equipment/export', [\App\Http\Controllers\StandardEquipmentManagementController::class, 'export'])
                ->name('standard-equipment.export');
            $router->post('standard-equipment/import', [\App\Http\Controllers\StandardEquipmentManagementController::class, 'import'])
                ->name('standard-equipment.import');
        });

        $router->post('yamma-yap-equipment/import', [\App\Http\Controllers\YammaYapEquipmentImportController::class, 'import'])
            ->name('yamma-yap-equipment.import');
        $router->post('labels/{label}/remove', [LabelController::class, 'remove'])->name('labels.remove');
        $router->post('labels/{label}/assign', [LabelController::class, 'assign'])->name('labels.assign');
        $router->get('labels/{label}/test/{vehicle}', [LabelController::class, 'testAgainstVehicle'])->name('labels.test');
        $router->apiResource('labels', LabelController::class);

        $router->apiResource('vehicle-trims', VehicleTrimController::class);
        $router->post('vehicle-trims/{vehicle_trim}/copy', [VehicleTrimController::class, 'copy'])->name('vehicle-trims.copy');
        $router->post('vehicle-trims/{vehicleTrim}/sync-template-fields', [VehicleTrimController::class, 'syncWithTemplate'])->name('vehicle-trims.sync-template-fields');

        $router->apiResource('catalog-offers', CatalogOfferController::class);

        $router->middleware([
            'enabled-feature:reservations',
            'permission:export-reservations'
        ])->group(function ($router) {
            $router->get('reservations/get-export', [ReservationController::class, 'getExport'])->name('reservations.get-export');
            $router->post('reservations/run-export', [ReservationController::class, 'runExport'])->name('reservations.run-export');
        });
        $router->apiResource('reservations', ReservationController::class)->only(['index', 'show', 'update', 'destroy'])->middleware('enabled-feature:reservations');
        $router->apiResource('reservation-statuses', ReservationStatusController::class)->only(['index', 'store', 'show', 'update', 'destroy'])->middleware('enabled-feature:reservations');

        $router->post('property-categories/{category:slug}/properties/reorder', [PropertyController::class, 'reorder'])->name('properties.reorder')->middleware('permission:manage-properties');
        $router->apiResource('property-categories/{category:slug}/properties', PropertyController::class)->middleware('permission:manage-properties');
        $router->apiResource('property-categories', PropertyCategoryController::class)->except('index')->middleware('permission:manage-property-categories');
        $router->get('property-categories', [PropertyCategoryController::class, 'index'])->name('property-categories.index')->middleware('permission:manage-properties');
        $router->get('property-categories-sitemap', [PropertyCategorySitemapController::class, 'index'])->middleware(['permission:edit-seo', 'enabled-feature:sitemap']);
        $router->put('property-categories-sitemap', [PropertyCategorySitemapController::class, 'update'])->middleware(['permission:edit-seo', 'enabled-feature:sitemap']);
        $router->get('franchises-sitemap', [FranchiseSitemapController::class, 'index'])->middleware(['permission:edit-seo', 'enabled-feature:sitemap']);
        $router->put('franchises-sitemap', [FranchiseSitemapController::class, 'update'])->middleware(['permission:edit-seo', 'enabled-feature:sitemap']);
        $router->get('sitemap/status', [SitemapController::class, 'status'])->middleware(['permission:edit-seo', 'enabled-feature:sitemap']);
        $router->post('sitemap/generate', [SitemapController::class, 'generate'])->middleware(['permission:edit-seo', 'enabled-feature:sitemap']);

        $router->get('colour-map', [ColourMapController::class, 'index'])->name('colour-map.index');
        $router->put('colour-map', [ColourMapController::class, 'update'])->name('colour-map.update');
        $router->post('colour-map/auto-map', [ColourMapController::class, 'autoMap'])->name('colour-map.auto-map');

        $router->get('sites/roles', [SiteUserController::class, 'roles'])->name('sites.roles');
        $router->get('api-logs', [ApiLogController::class, 'index']);
        $router->get('queue-process-logs', [QueueProcessLogController::class, 'index']);
        $router->get('queue-process-logs/{queueProcessLog}', [QueueProcessLogController::class, 'show']);

        $router->get('get-release-notes/{note}', [ReleaseNoteController::class, 'view'])->name('release-notes.view');
        $router->get('get-release-notes', [ReleaseNoteController::class, 'viewList'])->name('release-notes.view-all');

        $router->post('reports/vehicle/segments', [ReportController::class, 'vehicleSegments'])->name('reports.vehicle.segments');
        $router->post('reports/vehicle/performance', [ReportController::class, 'vehiclePerformance'])->name('reports.vehicle.performance');
        $router->post('reports/crm/year-overview', [ReportController::class, 'crmYearly'])->name('reports.crm.year-overview');
        $router->post('reports/crm/type-breakdown', [ReportController::class, 'typeBreakdown'])->name('reports.crm.type-breakdown');
        $router->post('reports/search-terms', [SearchTermReportController::class, 'index'])->name('reports.search-terms');

        // CRM enquiries
        $router->post('crm/enquiries/mark-as-spam', [EnquiryController::class, 'markAsSpam'])
            ->name('enquiries.mark-as-spam')
            ->middleware('permission:view-enquiries');
    });


Route::prefix('api')
    ->middleware([
        'api',
        InitializeTenancyByDomainInRequest::class,
    ])
    ->group(function (Router $router) {
        $router->get('/media/{mediaUse}/crop-size', (new AppMediaController())->cropMediaSize(...))->name('media.crop-size');
    });

Route::prefix('api/notifications/{tenant}/')
    ->as('tenant.notifications.')
    ->middleware([
        'api',
        InitializeTenancyByPath::class,
    ])
    ->group(function (Router $router) {
        $router->post('autos-on-show', [AutosOnShowNotificationController::class, 'store'])->name('autos-on-show');
        $router->middleware(['apiAuth:auto-imaging'])
            ->group(function (Router $router) {
                $router->get('auto-imaging', [AutoImagingNotificationController::class, 'index'])->name('auto-imaging.index');
                $router->post('auto-imaging', [AutoImagingNotificationController::class, 'store'])->name('auto-imaging.store');
            });
        $router->post('auto-trader-hub', [AutoTraderHubNotificationController::class, 'store'])->name('auto-trader-hub.store');
        $router->post('sales-force/vehicle', [SalesForceNotificationController::class, 'notifyVehicle'])->name('sales-force.notify-vehicle');

        $router->middleware([
            ApiAuthenticatedRequest::class,
            'throttle:autograb',
        ])->group(function (Router $router) {
            $router->post('autograb', [AutoGrabNotificationController::class, 'store'])->name('autograb.store');
        });
    });

Route::prefix('api/exports/{tenant}/')
    ->as('tenant.exports.')
    ->middleware([
        'api',
        InitializeTenancyByPath::class,
        'apiAuth:export-map',
    ])
    ->group(function (Router $router) {
        $router->get('{uuid}', [ExportMapApiController::class, 'download'])->name('download');
    });

Route::prefix('api/feeds/{tenant}/')
    ->as('tenant.feeds.')
    ->middleware([
        'api',
        InitializeTenancyByPath::class,
    ])
    ->group(function (Router $router) {
        $router->get('channable', [FeedController::class, 'channable'])->name('channable');
        $router->get('phyron', [PhyronController::class, 'vdp'])->name('phyron');
        $router->get('facebook', [FeedController::class, 'facebook'])->name('facebook');
        $router->get('google', [FeedController::class, 'google'])->name('google');
        $router->get('easichat', [FeedController::class, 'easichat'])->name('easichat');
    });


Route::prefix('api')
    ->as('tenant.')
    ->middleware([
        'api',
        InitializeTenancyByRequestData::class
    ])
    ->group(function (Router $router) {
        $router->post('proxy/valuations', [ValuationController::class, 'proxyRequest']);
    });


Route::prefix('api')
    ->middleware([
        'api',
    ])
    ->group(function (Router $router) {
        $router->get('/v1/phyron/sites', [PhyronController::class, 'index'])->name('phyron.sites');
        $router->post('/v1/phyron/notification', [PhyronController::class, 'store'])->name('phyron.notification');

        $router->middleware([
            InitializeTenancyBySiteInRequest::class,
            ApiAuthenticatedRequest::class
        ])->group(function (Router $router) {
            $router->get('/v1/storm/{tenant}/enquiries', [FeedController::class, 'stormEnquiries'])->name('storm-enquiries');
            $router->get('/v1/storm/{tenant}/enquiries/{type}/{id}', [FeedController::class, 'stormEnquiry'])->name('storm-enquiry');
            $router->get('/v1/out-and-about/{tenant}/stock', [OutAndAboutController::class, 'stock'])->name('out-and-about.stock');
            $router->post('/v1/{tenant}/vehicles/vrm-lookup', [ApiVehicleController::class, 'lookupByVrm'])->name('api.vehicles.vrm-lookup');
        });
    });


Route::prefix('api')
    ->middleware([
        'api',
        InitializeTenancyBySiteInRequest::class,
    ])
    ->group(function (Router $router) {
        $router->get('/v1/phyron/{tenant}/stock', [PhyronController::class, 'stock'])->name('phyron.stock');
        $router->get('/v1/phyron/{tenant}/vdp', [PhyronController::class, 'vdp'])->name('phyron.vdp');
    });
