<?php
declare(strict_types=1);

require_once __DIR__ . '/../parallel-odbc-typed-statement/TypedStatement.php';

/**
 * Private CLI prototype: keep the application's DM connector and DmBuilder.
 * No business connection config or globally installed PHP module uses this.
 */
final class PrivateOdbcDm extends \app\common\database\Dm
{
    protected function parseDsn(array $config): string
    {
        // Preserve the application's target validation before selecting the
        // approved private, password-free ODBC DSN.
        parent::parseDsn($config);
        return 'odbc:CDX_PRIVATE_AI';
    }

    protected function createPdo($dsn, $username, $password, $params)
    {
        if ($dsn !== 'odbc:CDX_PRIVATE_AI') {
            throw new InvalidArgumentException('Private ODBC DSN required');
        }
        $pdo = parent::createPdo($dsn, $username, $password, $params);
        if (!$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS,
            [TypedStatement::class, []])) {
            throw new RuntimeException('Private TypedStatement unavailable');
        }
        return $pdo;
    }
}
