<?php

namespace App\Modules\Inventory\Services;

use App\Modules\Inventory\Models\Warehouse;
use App\Modules\Inventory\Repositories\WarehouseRepository;
use Illuminate\Database\Eloquent\Collection;

final class InventoryWarehouseCatalogService
{
    public function __construct(
        private readonly WarehouseRepository $warehouses,
    ) {}

    /**
     * @return Collection<int, Warehouse>
     */
    public function listOrdered(): Collection
    {
        return $this->warehouses->listWithSectionsOrdered($this->tenantId());
    }

    private function tenantId(): int
    {
        $id = auth()->user()?->tenant_id;
        if ($id === null) {
            abort(403);
        }

        return (int) $id;
    }
}
