<?php

use App\Modules\Inventory\Controllers\CategoryController;
use App\Modules\Inventory\Controllers\ProductController;
use App\Modules\Inventory\Controllers\PurchaseController;
use App\Modules\Inventory\Controllers\SupplierController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth:sanctum', 'tenant', 'feature:inventory'])->group(function (): void {
    Route::middleware('company.permission:inventory.view')->group(function (): void {
        Route::get('/inventory/categories', [CategoryController::class, 'index']);
        Route::get('/inventory/products', [ProductController::class, 'index']);
        Route::get('/inventory/products/export/csv', [ProductController::class, 'exportCsv']);
        Route::get('/inventory/products/lookup', [ProductController::class, 'lookup']);
        Route::get('/inventory/products/low-stock', [ProductController::class, 'lowStock']);
        Route::get('/inventory/suppliers', [SupplierController::class, 'index']);
        Route::get('/inventory/purchases', [PurchaseController::class, 'index']);
        Route::get('/inventory/purchases/export/csv', [PurchaseController::class, 'exportCsv']);
        Route::get('/inventory/purchases/{purchase}', [PurchaseController::class, 'show']);
    });

    Route::middleware('company.permission:inventory.manage')->group(function (): void {
        Route::post('/inventory/categories', [CategoryController::class, 'store']);
        Route::patch('/inventory/categories/{category}', [CategoryController::class, 'update']);
        Route::post('/inventory/products', [ProductController::class, 'store']);
        Route::patch('/inventory/products/{product}', [ProductController::class, 'update']);
        Route::post('/inventory/products/{product}/adjust-stock', [ProductController::class, 'adjustStock']);
        Route::post('/inventory/suppliers', [SupplierController::class, 'store']);
        Route::patch('/inventory/suppliers/{supplier}', [SupplierController::class, 'update']);
        Route::post('/inventory/purchases', [PurchaseController::class, 'store']);
        Route::patch('/inventory/purchases/{purchase}', [PurchaseController::class, 'update']);
    });
});
