import { databaseTypes } from '../../../jdl/jhipster/index.mjs';
const { H2_DISK, H2_MEMORY, MARIADB, MSSQL, MYSQL, ORACLE, POSTGRESQL } = databaseTypes;
const H2_PROD_DATABASE_MODE = {
    [MYSQL]: ';MODE=MYSQL',
    [MARIADB]: ';MODE=LEGACY',
};
const h2GetProdDatabaseData = (databaseType, { extraOptions = '' }, { prodDatabaseType, buildDirectory, itests, localDirectory, protocolSuffix }) => {
    const data = {};
    if (protocolSuffix) {
        data.protocolSuffix = protocolSuffix;
    }
    if (H2_DISK === databaseType) {
        if (!localDirectory && !buildDirectory) {
            throw new Error(`'localDirectory' option should be provided for ${databaseType} databaseType`);
        }
        if (localDirectory) {
            localDirectory = `${localDirectory}/`;
        }
        else {
            localDirectory = `${buildDirectory}h2db/${itests ? 'testdb/' : 'db/'}`;
        }
    }
    if (itests && H2_MEMORY === databaseType) {
        data.port = ':12344';
    }
    const h2ProdDatabaseMode = prodDatabaseType ? H2_PROD_DATABASE_MODE[prodDatabaseType] ?? '' : '';
    return {
        ...data,
        localDirectory,
        extraOptions: `${extraOptions}${h2ProdDatabaseMode}`,
    };
};
const databaseData = {
    [MSSQL]: {
        name: 'SQL Server',
        protocolSuffix: 'sqlserver://',
        jdbcDriver: '',
        hibernateDialect: 'org.hibernate.dialect.SQLServer2012Dialect',
        port: ':1433;database=',
        defaultUsername: 'SA',
        defaultPassword: 'yourStrong(!)Password',
        jdbc: {
            extraOptions: ';encrypt=false',
        },
        r2dbc: {
            protocolSuffix: 'mssql://',
            port: ':1433/',
        },
    },
    [MARIADB]: {
        name: 'MariaDB',
        protocolSuffix: 'mariadb://',
        jdbcDriver: 'org.mariadb.jdbc.Driver',
        hibernateDialect: 'org.hibernate.dialect.MariaDB103Dialect',
        port: ':3306/',
        extraOptions: '?useLegacyDatetimeCode=false',
        defaultUsername: 'root',
        constraintNameMaxLength: 64,
        tableNameMaxLength: 64,
        r2dbc: {
            protocolSuffix: 'mysql://',
        },
    },
    [MYSQL]: {
        name: 'MySQL',
        protocolSuffix: 'mysql://',
        jdbcDriver: 'com.mysql.cj.jdbc.Driver',
        hibernateDialect: 'org.hibernate.dialect.MySQL8Dialect',
        tableNameMaxLength: 64,
        constraintNameMaxLength: 64,
        port: ':3306/',
        extraOptions: '?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&createDatabaseIfNotExist=true',
        defaultUsername: 'root',
    },
    [ORACLE]: {
        name: 'Oracle',
        protocolSuffix: 'oracle:thin:@',
        jdbcDriver: 'oracle.jdbc.OracleDriver',
        hibernateDialect: 'org.hibernate.dialect.Oracle12cDialect',
        port: ':1521:',
        defaultUsername: 'system',
        defaultPassword: 'oracle',
        defaultDatabaseName: 'xe',
        constraintNameMaxLength: 128,
        tableNameMaxLength: 128,
    },
    [POSTGRESQL]: {
        name: 'PostgreSQL',
        protocolSuffix: 'postgresql://',
        jdbcDriver: 'org.postgresql.Driver',
        hibernateDialect: 'org.hibernate.dialect.PostgreSQLDialect',
        port: ':5432/',
        constraintNameMaxLength: 63,
        tableNameMaxLength: 63,
    },
    [H2_DISK]: {
        name: 'H2Disk',
        protocolSuffix: 'h2:file:',
        jdbcDriver: 'org.h2.Driver',
        hibernateDialect: 'org.hibernate.dialect.H2Dialect',
        getData: options => h2GetProdDatabaseData(H2_DISK, { extraOptions: ';DB_CLOSE_DELAY=-1' }, options),
        r2dbc: {
            protocolSuffix: 'h2:file:///',
        },
    },
    [H2_MEMORY]: {
        name: 'H2Memory',
        protocolSuffix: 'h2:mem:',
        jdbcDriver: 'org.h2.Driver',
        hibernateDialect: 'org.hibernate.dialect.H2Dialect',
        getData: options => h2GetProdDatabaseData(H2_MEMORY, { extraOptions: ';DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE' }, options),
        r2dbc: {
            protocolSuffix: 'h2:mem:///',
        },
    },
};
export default databaseData;
export function getDatabaseData(databaseType) {
    if (databaseData[databaseType] === undefined) {
        throw new Error(`Database data not found for database ${databaseType}`);
    }
    return databaseData[databaseType];
}
export const getDBCExtraOption = databaseType => {
    const databaseDataForType = databaseData[databaseType];
    const { extraOptions = '' } = databaseDataForType;
    return extraOptions;
};
