"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getColumnType = getColumnType;
const create_model_metadata_dto_1 = require("../dtos/create-model-metadata.dto");
const LONG_TEXT_MAP = {
    [create_model_metadata_dto_1.DatasourceType.postgres]: { type: "text" },
    [create_model_metadata_dto_1.DatasourceType.mssql]: { type: "nvarchar", length: "max" },
    [create_model_metadata_dto_1.DatasourceType.mysql]: { type: "longtext" },
    [create_model_metadata_dto_1.DatasourceType.mariadb]: { type: "longtext" },
    [create_model_metadata_dto_1.DatasourceType.oracle]: { type: "clob" },
};
const SIMPLE_JSON_LARGE_TEXT_MAP = {
    [create_model_metadata_dto_1.DatasourceType.postgres]: {},
    [create_model_metadata_dto_1.DatasourceType.mssql]: {},
    [create_model_metadata_dto_1.DatasourceType.mysql]: {
        type: "longtext",
        transformer: {
            to: (value) => (value !== undefined && value !== null ? JSON.stringify(value) : value),
            from: (value) => (value !== null && value !== undefined ? JSON.parse(value) : value),
        },
    },
    [create_model_metadata_dto_1.DatasourceType.mariadb]: {
        type: "longtext",
        transformer: {
            to: (value) => (value !== undefined && value !== null ? JSON.stringify(value) : value),
            from: (value) => (value !== null && value !== undefined ? JSON.parse(value) : value),
        },
    },
    [create_model_metadata_dto_1.DatasourceType.oracle]: { type: "clob" },
};
const DECIMAL_MAP = {
    [create_model_metadata_dto_1.DatasourceType.postgres]: { type: "float4" },
    [create_model_metadata_dto_1.DatasourceType.mssql]: { type: "float" },
    [create_model_metadata_dto_1.DatasourceType.mysql]: { type: "float" },
    [create_model_metadata_dto_1.DatasourceType.mariadb]: { type: "float" },
    [create_model_metadata_dto_1.DatasourceType.oracle]: { type: "float" },
};
const solidCoreDbType = Object.values(create_model_metadata_dto_1.DatasourceType).includes(process.env.SOLID_CORE_DB_TYPE)
    ? process.env.SOLID_CORE_DB_TYPE
    : create_model_metadata_dto_1.DatasourceType.postgres;
function getColumnType(solidType) {
    switch (solidType) {
        case "longText":
        case "richText":
            return LONG_TEXT_MAP[solidCoreDbType];
        case "simpleJsonLargeText":
            return SIMPLE_JSON_LARGE_TEXT_MAP[solidCoreDbType];
        case "decimal":
            return DECIMAL_MAP[solidCoreDbType];
        default:
            return {};
    }
}
//# sourceMappingURL=typeorm-db-helper.js.map