<?php

use App\Modules\Sales\Controllers\SalesOrderBulkOperationsController;
use App\Modules\Sales\Controllers\SalesOrderOperationalController;
use App\Modules\Sales\Controllers\SalesOrderPageController;
use App\Modules\Sales\Controllers\SalesReturnPageController;
use Illuminate\Support\Facades\Route;

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

    Route::get('/{sales_order}', [SalesOrderPageController::class, 'show'])
        ->middleware('can:sales.orders.view')
        ->name('show');

    Route::post('/{sales_order}/allocate', [SalesOrderOperationalController::class, 'allocate'])
        ->middleware('can:allocate,sales_order')
        ->name('allocate.store');

    Route::post('/{sales_order}/fulfill', [SalesOrderOperationalController::class, 'fulfill'])
        ->middleware('can:fulfill,sales_order')
        ->name('fulfill.store');

    Route::post('/{sales_order}/cancel', [SalesOrderOperationalController::class, 'cancel'])
        ->middleware('can:cancel,sales_order')
        ->name('cancel.store');

    Route::post('/bulk/allocate-max', [SalesOrderBulkOperationsController::class, 'allocateMax'])
        ->middleware('can:sales.orders.view')
        ->name('bulk.allocate-max');

    Route::post('/bulk/fulfill-max', [SalesOrderBulkOperationsController::class, 'fulfillMax'])
        ->middleware('can:sales.orders.view')
        ->name('bulk.fulfill-max');
});

Route::prefix('sales/returns')->name('sales.returns.')->group(function (): void {
    Route::get('/{sales_return}', [SalesReturnPageController::class, 'show'])
        ->middleware('can:view,sales_return')
        ->name('show');
});
