<?php

declare(strict_types=1);

namespace App\Framework\Database\UnitOfWork;

use App\Framework\Database\DatabaseManager;
use App\Framework\Database\HydratorInterface;
use App\Framework\Database\IdentityMap;
use App\Framework\Database\Metadata\MetadataRegistry;
use App\Framework\Database\TypeConverter;

/**
 * Factory for creating UnitOfWork instances
 */
final class UnitOfWorkFactory
{
    public static function create(
        DatabaseManager $databaseManager,
        MetadataRegistry $metadataRegistry,
        IdentityMap $identityMap,
        HydratorInterface $hydrator,
        TypeConverter $typeConverter
    ): UnitOfWork {
        $changeTracker = new ChangeTracker($metadataRegistry);
        $bulkOperations = new BulkOperations($metadataRegistry, $typeConverter);

        return new UnitOfWork(
            databaseManager: $databaseManager,
            changeTracker: $changeTracker,
            metadataRegistry: $metadataRegistry,
            identityMap: $identityMap,
            hydrator: $hydrator,
            typeConverter: $typeConverter,
            bulkOperations: $bulkOperations
        );
    }
}
