<?php

namespace App\Modules\Inventory\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Inventory\Models\Warehouse;
use App\Modules\Inventory\Services\InventoryWarehouseCatalogService;
use Illuminate\Http\Request;
use Illuminate\View\View;

class WarehousePageController extends Controller
{
    public function __construct(
        private readonly InventoryWarehouseCatalogService $catalog,
    ) {}

    public function index(Request $request): View
    {
        $this->authorize('viewAny', Warehouse::class);

        return view('pages.inventory.warehouses.index', [
            'warehouses' => $this->catalog->paginateForIndex($request),
        ]);
    }

    public function show(Warehouse $warehouse): View
    {
        $this->authorize('view', $warehouse);
        $warehouse->load([
            'sections' => static fn ($q) => $q->orderBy('sort_order')->orderBy('code'),
        ]);

        return view('pages.inventory.warehouses.show', [
            'warehouse' => $warehouse,
        ]);
    }
}
