"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertValue = convertValue;
function convertValue(oldType, newType, value) {
    switch (newType) {
        case "string": {
            switch (oldType) {
                case "json": {
                    return JSON.stringify(value);
                }
                default: {
                    return value.toString();
                }
            }
        }
        case "number": {
            switch (oldType) {
                case "string":
                case "json": {
                    const parsed = parseFloat(value);
                    if (isNaN(parsed)) {
                        return 0;
                    }
                    return parsed;
                }
                default: {
                    return value;
                }
            }
        }
        case "boolean": {
            switch (oldType) {
                case "json":
                case "string": {
                    return value === "true" || value === "1";
                }
                default: {
                    return !!value;
                }
            }
        }
        default: {
            return value;
        }
    }
}
