"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SnowflakePostgresPlugin = exports.SnowflakePostgresPluginVersions = 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");
exports.SnowflakePostgresPluginVersions = {
    V1: '0.0.1'
};
const BASE_HOST = {
    label: 'Host',
    name: 'connection.host',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    placeholder: 'xxxx.us-west-2.aws.postgres.snowflake.app',
    rules: [{ required: true, message: 'Host is required' }]
};
const BASE_PORT = {
    label: 'Port',
    name: 'connection.port',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    dataType: index_js_1.InputDataType.NUMBER,
    initialValue: 5432,
    rules: [{ required: true, message: 'Port is required' }]
};
const BASE_DATABASE_NAME = {
    label: 'Database name',
    name: 'connection.databaseName',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    rules: [{ required: true, message: 'Database name is required' }]
};
const BASE_DATABASE_USERNAME = {
    label: 'Database username',
    name: 'connection.username',
    componentType: index_js_1.FormComponentType.INPUT_TEXT
};
const BASE_DATABASE_PASSWORD = {
    label: 'Database password',
    name: 'connection.password',
    componentType: index_js_1.FormComponentType.INPUT_TEXT,
    dataType: index_js_1.InputDataType.PASSWORD
};
const BASE_SELFSIGNED_SSL = {
    label: 'Use a self-signed SSL certificate',
    name: 'connection.useSelfSignedSsl',
    componentType: index_js_1.FormComponentType.CHECKBOX,
    tooltip: {
        markdownText: 'Use a self-signed SSL certificate'
    }
};
const BASE_SERVER_CA = {
    label: 'Server CA',
    name: 'connection.ca',
    componentType: index_js_1.FormComponentType.CODE_EDITOR,
    language: index_js_1.EditorLanguage.TEXT,
    placeholder: '-----BEGIN CERTIFICATE-----\n' +
        'MIIC/jCCAeYCCQDLwS4pIwJC3zANBgkqhkiG9w0BAQsFADBBMQswCQYDVQQGEwJV\n' +
        '...\n' +
        '-----END CERTIFICATE-----'
};
const BASE_CLIENT_KEY = {
    label: 'Client key',
    name: 'connection.key',
    componentType: index_js_1.FormComponentType.CODE_EDITOR,
    language: index_js_1.EditorLanguage.TEXT,
    placeholder: '-----BEGIN RSA PRIVATE KEY-----\n' +
        'BAoMBFRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCpvozN05Ou\n' +
        '...\n' +
        '-----END RSA PRIVATE KEY-----'
};
const BASE_CLIENT_CERT = {
    label: 'Client cert',
    name: 'connection.cert',
    componentType: index_js_1.FormComponentType.CODE_EDITOR,
    language: index_js_1.EditorLanguage.TEXT,
    placeholder: '-----BEGIN CERTIFICATE-----\n' +
        'Ur2LYWdrVjqlS/wJyVIze15FMf7sgl+RINsLbQDLwS4pIwJC3zANBgkqhkiG9w0B\n' +
        '...\n' +
        '-----END CERTIFICATE-----'
};
exports.SnowflakePostgresPlugin = {
    id: 'snowflakepostgres',
    name: 'Snowflake Postgres',
    moduleName: 'SnowflakePostgresPlugin',
    modulePath: 'plugins/snowflakepostgres/SnowflakePostgresPlugin',
    iconLocation: `${constants_js_1.PUBLIC_INTEGRATIONS_LOGO_URL}/snowflake.png`,
    docsUrl: `${constants_js_1.DOCS_BASE_URL}/snowflake-postgres`,
    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: exports.SnowflakePostgresPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.INPUT_TEXT,
                        placeholder: 'Snowflake Postgres Production',
                        rules: [{ required: true, message: 'Display name is required' }]
                    },
                    {
                        label: 'Connection method',
                        name: 'connectionType',
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        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: exports.SnowflakePostgresPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.DYNAMIC_INPUT_TEXT,
                        placeholder: `postgres://[:user]:[:password]@[:host]:[:port]/[:database]`,
                        tooltip: {
                            markdownText: 'PostgreSQL-compatible connection URI for your Snowflake Postgres instance'
                        },
                        rules: [{ required: true, message: 'URI is required' }],
                        display: {
                            show: {
                                connectionType: ['url']
                            }
                        }
                    },
                    // HOST
                    {
                        ...BASE_HOST,
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // PORT
                    {
                        ...BASE_PORT,
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // DATABASE NAME
                    {
                        ...BASE_DATABASE_NAME,
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // DATABASE USERNAME
                    {
                        ...BASE_DATABASE_USERNAME,
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // DATABASE PASSWORD
                    {
                        ...BASE_DATABASE_PASSWORD,
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // SSL is always enabled for Snowflake - no checkbox shown.
                    // Self-signed SSL certificate option
                    {
                        ...BASE_SELFSIGNED_SSL,
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        display: {
                            show: {
                                connectionType: ['fields']
                            }
                        }
                    },
                    // SERVER CA
                    {
                        ...BASE_SERVER_CA,
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        display: {
                            show: {
                                'connection.useSelfSignedSsl': ['true'],
                                connectionType: ['fields']
                            }
                        }
                    },
                    // CLIENT KEY
                    {
                        ...BASE_CLIENT_KEY,
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        display: {
                            show: {
                                'connection.useSelfSignedSsl': ['true'],
                                connectionType: ['fields']
                            }
                        }
                    },
                    // CLIENT CERT
                    {
                        ...BASE_CLIENT_CERT,
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        display: {
                            show: {
                                'connection.useSelfSignedSsl': ['true'],
                                connectionType: ['fields']
                            }
                        }
                    }
                ]
            }
        ]
    },
    actionTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Parameters ($1, $2, ...)',
                        name: 'parameters',
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        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: exports.SnowflakePostgresPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.CODE_EDITOR,
                        language: index_js_1.EditorLanguage.SQL,
                        initialValue: index_js_1.DB_SQL_INITIAL_TEXT
                    }
                ]
            },
            {
                name: 'advanced:main',
                items: [
                    {
                        label: 'Use parameterized SQL',
                        name: 'usePreparedSql',
                        startVersion: exports.SnowflakePostgresPluginVersions.V1,
                        componentType: index_js_1.FormComponentType.SWITCH,
                        initialValue: true,
                        tooltip: {
                            markdownText: constants_js_1.PARAMETERIZED_SQL_DESCRIPTION
                        },
                        display: {
                            show: {
                                parameters: ['undefined']
                            }
                        }
                    }
                ]
            }
        ]
    }
};
//# sourceMappingURL=snowflakepostgres.js.map