<?php

use App\Modules\Inventory\Stock\Controllers\InventoryStockTransferPageController;
use App\Modules\Inventory\Controllers\InventoryAttributeCreateController;
use App\Modules\Inventory\Controllers\InventoryAttributePageController;
use App\Modules\Inventory\Controllers\InventoryVisibilityPageController;
use App\Modules\Inventory\Controllers\ItemCatalogPageController;
use App\Modules\Inventory\Controllers\ItemCreateController;
use App\Modules\Inventory\Controllers\ItemCategoryCreateController;
use App\Modules\Inventory\Controllers\ItemCategoryPageController;
use App\Modules\Inventory\Controllers\WarehouseCreateController;
use App\Modules\Inventory\Controllers\WarehouseDeactivateController;
use App\Modules\Inventory\Controllers\WarehousePageController;
use Illuminate\Support\Facades\Route;

Route::prefix('inventory/warehouses')->name('inventory.warehouses.')->group(function (): void {
    Route::get('/', [WarehousePageController::class, 'index'])
        ->middleware('can:inventory.warehouses.view')
        ->name('index');

    Route::get('/create', [WarehouseCreateController::class, 'create'])
        ->middleware('can:create,App\Modules\Inventory\Models\Warehouse')
        ->name('create');

    Route::post('/', [WarehouseCreateController::class, 'store'])
        ->middleware('can:create,App\Modules\Inventory\Models\Warehouse')
        ->name('store');

    Route::get('/{warehouse}', [WarehousePageController::class, 'show'])
        ->middleware('can:inventory.warehouses.view')
        ->name('show');

    Route::post('/{warehouse}/deactivate', [WarehouseDeactivateController::class, 'store'])
        ->middleware('can:deactivate,warehouse')
        ->name('deactivate.store');
});

Route::prefix('inventory/items')->name('inventory.items.')->group(function (): void {
    Route::get('/', [ItemCatalogPageController::class, 'index'])
        ->middleware('can:inventory.catalog.view')
        ->name('index');

    Route::get('/create', [ItemCreateController::class, 'create'])
        ->middleware('can:create,App\Modules\Inventory\Models\Item')
        ->name('create');

    Route::post('/', [ItemCreateController::class, 'store'])
        ->middleware('can:create,App\Modules\Inventory\Models\Item')
        ->name('store');

    Route::get('/{item}', [ItemCatalogPageController::class, 'show'])
        ->middleware('can:inventory.catalog.view')
        ->name('show');
});

Route::prefix('inventory/categories')->name('inventory.categories.')->group(function (): void {
    Route::get('/', [ItemCategoryPageController::class, 'index'])
        ->middleware('can:inventory.catalog.view')
        ->name('index');

    Route::get('/create', [ItemCategoryCreateController::class, 'create'])
        ->middleware('can:create,App\Modules\Inventory\Models\ItemCategory')
        ->name('create');

    Route::post('/', [ItemCategoryCreateController::class, 'store'])
        ->middleware('can:create,App\Modules\Inventory\Models\ItemCategory')
        ->name('store');
});

Route::prefix('inventory/attributes')->name('inventory.attributes.')->group(function (): void {
    Route::get('/', [InventoryAttributePageController::class, 'index'])
        ->middleware('can:inventory.catalog.view')
        ->name('index');

    Route::get('/create', [InventoryAttributeCreateController::class, 'create'])
        ->middleware('can:create,App\Modules\Inventory\Models\InventoryAttribute')
        ->name('create');

    Route::post('/', [InventoryAttributeCreateController::class, 'store'])
        ->middleware('can:create,App\Modules\Inventory\Models\InventoryAttribute')
        ->name('store');
});

Route::prefix('inventory/visibility')->name('inventory.visibility.')->group(function (): void {
    Route::get('/', [InventoryVisibilityPageController::class, 'index'])
        ->middleware('can:inventory.stock.view')
        ->name('index');
});

Route::prefix('inventory/stock-transfers')->name('inventory.stock-transfers.')->group(function (): void {
    Route::get('/{transfer}', [InventoryStockTransferPageController::class, 'show'])
        ->middleware('can:view,transfer')
        ->name('show');
});
