<?php

namespace App\Modules\Inventory\Stock\Repositories;

use App\Modules\Inventory\Stock\Models\InventoryStockTransfer;

class InventoryStockTransferRepository
{
    public function lockByIdForTenant(int $tenantId, int $id): ?InventoryStockTransfer
    {
        return InventoryStockTransfer::withoutGlobalScopes()
            ->where('tenant_id', $tenantId)
            ->whereKey($id)
            ->lockForUpdate()
            ->first();
    }

    public function save(InventoryStockTransfer $transfer): void
    {
        $transfer->save();
    }

    /**
     * @param  array<string, mixed>  $attributes
     */
    public function createDraft(array $attributes): InventoryStockTransfer
    {
        return InventoryStockTransfer::withoutGlobalScopes()->create($attributes);
    }
}
