<?php
declare(strict_types=1);

// Phinx config — uses the same .env as the app.
require __DIR__ . '/../vendor/autoload.php';

$envPath = dirname(__DIR__);
if (file_exists($envPath . '/.env')) {
    \Dotenv\Dotenv::createImmutable($envPath)->safeLoad();
}

$env = static fn(string $k, $d = null) => $_ENV[$k] ?? getenv($k) ?: $d;

return [
    'paths' => [
        'migrations' => __DIR__ . '/migrations',
        'seeds'      => __DIR__ . '/seeds',
    ],
    'environments' => [
        'default_migration_table' => '_phinx_migrations',
        'default_environment'     => 'development',
        'development' => [
            'adapter' => 'mysql',
            'host'    => $env('DB_HOST', 'localhost'),
            'name'    => $env('DB_NAME', 'orchview2'),
            'user'    => $env('DB_USER', 'root'),
            'pass'    => $env('DB_PASSWORD', ''),
            'port'    => 3306,
            'charset' => $env('DB_CHARSET', 'utf8mb4'),
            'collation' => 'utf8mb4_unicode_ci',
        ],
        'production' => [
            'adapter' => 'mysql',
            'host'    => $env('DB_HOST', 'localhost'),
            'name'    => $env('DB_NAME', 'orchview2'),
            'user'    => $env('DB_USER', 'root'),
            'pass'    => $env('DB_PASSWORD', ''),
            'port'    => 3306,
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
        ],
    ],
    'version_order' => 'creation',
];
