<?php

namespace Modules\Inventory\Repositories;

use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Modules\Core\Enums\StatusEnum;
use Modules\Inventory\DTO\ProductUnitConversionFilter;
use Modules\Inventory\Models\ProductUnitConversion;

class UnitConversionRepository
{
    public function find(int $id): ProductUnitConversion
    {
        return ProductUnitConversion::query()
            ->with([
                'product:id,name,inventory_department_id',
                'product.inventoryDepartment:id,name',
                'baseUnit:id,name',
                'levelOneUnit:id,name',
                'levelTwoUnit:id,name',
                'levelThreeUnit:id,name',
            ])
            ->findOrFail($id);
    }

    public function create(array $data): ProductUnitConversion
    {
        return ProductUnitConversion::query()->create($data);
    }

    public function update(ProductUnitConversion $conversion, array $data): ProductUnitConversion
    {
        $conversion->update($data);

        return $conversion;
    }

    public function updatePriority(int $id,int $priority): void
    {
        ProductUnitConversion::query()
            ->where('id', $id)
            ->update([
                'priority' => $priority,
            ]);
    }
}
