<?php

declare(strict_types=1);

namespace PpPhp\Core\Database\Dialect;

final class DatabaseDialectRegistry
{
    public static function forConfig(array $config): DatabaseDialectInterface
    {
        $type = strtolower((string)($config['type'] ?? 'mysql'));
        return match ($type) {
            'mysql', 'mariadb' => new MySqlDialect($type),
            'tidb' => new TiDbDialect(),
            'pgsql', 'postgres', 'postgresql' => new PostgreSqlDialect(),
            'cockroachdb', 'cockroach', 'crdb' => new CockroachDbDialect(),
            'sqlite' => new SQLiteDialect(),
            'sqlsrv', 'mssql', 'sqlserver' => new SqlServerDialect(),
            'oci', 'oracle' => new OracleDialect(),
            default => new UnsupportedDialect($type),
        };
    }
}
