<?php

namespace App\Modules\Inventory\Repositories;

use App\Modules\Inventory\Models\InventoryAttribute;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;

class InventoryAttributeRepository
{
    /**
     * @return LengthAwarePaginator<int, InventoryAttribute>
     */
    public function paginatedWithOptionsCount(int $perPage = 40): LengthAwarePaginator
    {
        return InventoryAttribute::query()
            ->withCount('options')
            ->orderBy('code')
            ->paginate($perPage);
    }

    /**
     * @param  array<string, mixed>  $attributes
     */
    public function create(int $tenantId, array $attributes): InventoryAttribute
    {
        return InventoryAttribute::query()->create(array_merge(['tenant_id' => $tenantId], $attributes));
    }
}
