"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedshiftPlugin = void 0;
const index_js_1 = require("../../types/index.js");
const constants_js_1 = require("./constants.js");
const db_js_1 = require("./shared/db.js");
const RedshiftPluginVersions = {
    V1: '0.0.1',
    V2: '0.0.2',
    V6: '0.0.6',
    V7: '0.0.7',
    V8: '0.0.8'
};
const BASE_HOST = {
    label: 'Host',
    name: 'endpoint.host',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    placeholder: 'superblocks-redshift-dev.clyn5z3du7tf.us-west-2.redshift.amazonaws.com',
    rules: [{ required: true, message: 'Host is required' }]
};
const BASE_PORT = {
    label: 'Port',
    name: 'endpoint.port',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    initialValue: '5439',
    dataType: index_js_1.InputDataType.NUMBER
};
const BASE_SCHEMA = {
    label: 'Schema',
    name: 'authentication.custom.databaseSchema.value',
    initialValue: 'public',
    componentType: index_js_1.FormComponentType.INPUT_TEXT
};
const BASE_DATABASE_NAME = {
    label: 'Database name',
    name: 'authentication.custom.databaseName.value',
    componentType: index_js_1.FormComponentType.INPUT_TEXT
};
const BASE_DATABASE_USERNAME = {
    label: 'Database username',
    name: 'authentication.username',
    componentType: index_js_1.FormComponentType.INPUT_TEXT
};
const BASE_DATABASE_PASSWORD = {
    label: 'Database password',
    name: 'authentication.password',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    dataType: index_js_1.InputDataType.PASSWORD
};
const BASE_ENABLE_SSL = {
    label: 'Enable SSL',
    name: 'connection.useSsl',
    initialValue: 'checked',
    componentType: index_js_1.FormComponentType.CHECKBOX
};
exports.RedshiftPlugin = {
    id: 'redshift',
    name: 'Amazon Redshift',
    moduleName: 'RedshiftPlugin',
    modulePath: 'plugins/redshift/RedshiftPlugin',
    iconLocation: `${constants_js_1.PUBLIC_INTEGRATIONS_LOGO_URL}/redshift.png`,
    docsUrl: `${constants_js_1.DOCS_BASE_URL}/aws-redshift`,
    type: index_js_1.PluginType.DB,
    responseType: index_js_1.PluginResponseType.TABLE,
    hasRawRequest: true,
    hasMetadata: true,
    rawRequestName: 'Executed SQL',
    datasourceTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Display name',
                        name: 'name',
                        startVersion: RedshiftPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        placeholder: 'Redshift Prod Cluster',
                        rules: [{ required: true, message: 'Display name is required' }]
                    },
                    {
                        label: 'Connection method',
                        name: 'connectionType',
                        startVersion: RedshiftPluginVersions.V7,
                        componentType: index_js_1.FormComponentType.DROPDOWN,
                        initialValue: 'fields',
                        rules: [{ required: true }],
                        options: Object.entries(db_js_1.CONNECTION_METHODS_AND_DISPLAY_NAMES).map(([value, displayName]) => (0, db_js_1.makeDropdownItem)(value, displayName))
                    },
                    {
                        label: 'URI',
                        name: 'connectionUrl',
                        startVersion: RedshiftPluginVersions.V7,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        placeholder: `redshift://[:username]:[:password]@[:host]:[:port]/[:database]`,
                        rules: [{ required: true, message: 'URI is required' }],
                        display: {
                            show: {
                                connectionType: ['url']
                            }
                        }
                    },
                    // HOST
                    {
                        ...BASE_HOST,
                        startVersion: RedshiftPluginVersions.V1,
                        endVersion: RedshiftPluginVersions.V6
                    },
                    {
                        ...BASE_HOST,
                        startVersion: RedshiftPluginVersions.V7,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // PORT
                    {
                        ...BASE_PORT,
                        startVersion: RedshiftPluginVersions.V1,
                        endVersion: RedshiftPluginVersions.V6
                    },
                    {
                        ...BASE_PORT,
                        startVersion: RedshiftPluginVersions.V7,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // Schema
                    {
                        ...BASE_SCHEMA,
                        startVersion: RedshiftPluginVersions.V1,
                        endVersion: RedshiftPluginVersions.V6
                    },
                    {
                        ...BASE_SCHEMA,
                        startVersion: RedshiftPluginVersions.V7,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // DATABASE NAME
                    {
                        ...BASE_DATABASE_NAME,
                        startVersion: RedshiftPluginVersions.V1,
                        endVersion: RedshiftPluginVersions.V6
                    },
                    {
                        ...BASE_DATABASE_NAME,
                        startVersion: RedshiftPluginVersions.V7,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // DATABASE USERNAME
                    {
                        ...BASE_DATABASE_USERNAME,
                        startVersion: RedshiftPluginVersions.V1,
                        endVersion: RedshiftPluginVersions.V6
                    },
                    {
                        ...BASE_DATABASE_USERNAME,
                        startVersion: RedshiftPluginVersions.V7,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // DATABASE PASSWORD
                    {
                        ...BASE_DATABASE_PASSWORD,
                        startVersion: RedshiftPluginVersions.V1,
                        endVersion: RedshiftPluginVersions.V6
                    },
                    {
                        ...BASE_DATABASE_PASSWORD,
                        startVersion: RedshiftPluginVersions.V7,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // Enable SSL
                    {
                        ...BASE_ENABLE_SSL,
                        startVersion: RedshiftPluginVersions.V1,
                        endVersion: RedshiftPluginVersions.V6
                    },
                    {
                        ...BASE_ENABLE_SSL,
                        startVersion: RedshiftPluginVersions.V7,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    }
                ]
            }
        ]
    },
    actionTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Parameters ($1, $2, ...)',
                        name: 'parameters',
                        startVersion: RedshiftPluginVersions.V8,
                        ldFlag: 'clark.parameterized-apis.v2.enabled',
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        placeholder: '[param1, param2, ...]',
                        tooltip: {
                            markdownText: 'JavaScript expression that evaluates to an array of parameter values. Use `$1`, `$2`, etc. in your SQL query to reference these parameters.'
                        }
                    },
                    {
                        label: '', // Query
                        name: 'body',
                        startVersion: RedshiftPluginVersions.V1,
                        endVersion: RedshiftPluginVersions.V7,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.SQL,
                        initialValue: constants_js_1.SQL_INITIAL_TEXT
                    },
                    {
                        label: '', // Query
                        name: 'body',
                        startVersion: RedshiftPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.SQL,
                        initialValue: constants_js_1.SQL_INITIAL_TEXT
                    }
                ]
            },
            {
                name: 'advanced:main',
                items: [
                    {
                        label: 'Use parameterized SQL',
                        name: 'usePreparedSql',
                        startVersion: RedshiftPluginVersions.V6,
                        endVersion: RedshiftPluginVersions.V7,
                        componentType: index_js_1.FormComponentType.SWITCH,
                        initialValue: true,
                        tooltip: {
                            markdownText: constants_js_1.PARAMETERIZED_SQL_DESCRIPTION
                        }
                    },
                    {
                        label: 'Use parameterized SQL',
                        name: 'usePreparedSql',
                        startVersion: RedshiftPluginVersions.V8,
                        componentType: index_js_1.FormComponentType.SWITCH,
                        initialValue: true,
                        tooltip: {
                            markdownText: constants_js_1.PARAMETERIZED_SQL_DESCRIPTION
                        },
                        display: {
                            show: {
                                parameters: ['undefined']
                            }
                        }
                    }
                ]
            }
        ]
    }
};
//# sourceMappingURL=redshift.js.map