<?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\View\View;

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

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

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

    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,
        ]);
    }
}
