import { EditorLanguage, FormComponentType, PluginResponseType, PluginType } from '../../types/index.js';
import { PUBLIC_INTEGRATIONS_LOGO_URL, DOCS_BASE_URL } from './constants.js';
const MongoDBPluginVersions = {
    V1: '0.0.1',
    V7: '0.0.7'
};
var MongoDBOperationType;
(function (MongoDBOperationType) {
    MongoDBOperationType["aggregate"] = "aggregate";
    MongoDBOperationType["count"] = "count";
    MongoDBOperationType["deleteOne"] = "deleteOne";
    MongoDBOperationType["deleteMany"] = "deleteMany";
    MongoDBOperationType["distinct"] = "distinct";
    MongoDBOperationType["find"] = "find";
    MongoDBOperationType["findOne"] = "findOne";
    MongoDBOperationType["insertOne"] = "insertOne";
    MongoDBOperationType["insertMany"] = "insertMany";
    MongoDBOperationType["listCollections"] = "listCollections";
    MongoDBOperationType["replaceOne"] = "replaceOne";
    MongoDBOperationType["updateOne"] = "updateOne";
    MongoDBOperationType["updateMany"] = "updateMany";
})(MongoDBOperationType || (MongoDBOperationType = {}));
export const MongoDBPlugin = {
    id: 'mongodb',
    name: 'MongoDB',
    moduleName: 'MongoDBPlugin',
    modulePath: 'plugins/mongodb/MongoDBPlugin',
    iconLocation: `${PUBLIC_INTEGRATIONS_LOGO_URL}/mongodb.png`,
    docsUrl: `${DOCS_BASE_URL}/mongodb`,
    type: PluginType.DB,
    responseType: PluginResponseType.JSON,
    hasRawRequest: true,
    hasMetadata: true,
    rawRequestName: 'Executed operation',
    datasourceTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Display name',
                        name: 'name',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.INPUT_TEXT,
                        rules: [{ required: true, message: 'Display name is required' }]
                    },
                    {
                        label: 'Connection URI',
                        name: 'endpoint.host',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.INPUT_TEXT,
                        placeholder: 'mongodb+srv://<username>:<password>@<host>/?retryWrites=true&w=majority',
                        rules: [{ required: true, message: 'Connection URI is required' }],
                        tooltip: {
                            markdownText: 'Connection URI used to connect to a MongoDB deployment. Format: ' +
                                '`mongodb+srv://<username>:<password>@<host>/?retryWrites=true&w=majority` ' +
                                '[Connection URI Docs](https://docs.mongodb.com/manual/reference/connection-string/)'
                        }
                    },
                    {
                        label: 'Database name',
                        name: 'authentication.custom.databaseName.value',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.INPUT_TEXT,
                        rules: [{ required: true, message: 'Database Name is required' }]
                    },
                    {
                        label: 'Use a self-signed SSL certificate',
                        name: 'connection.useSelfSignedSsl',
                        startVersion: MongoDBPluginVersions.V7,
                        componentType: FormComponentType.CHECKBOX
                    },
                    {
                        label: 'Server CA',
                        name: 'connection.ca',
                        startVersion: MongoDBPluginVersions.V7,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.TEXT,
                        placeholder: '-----BEGIN CERTIFICATE-----\n' +
                            'MIIC/jCCAeYCCQDLwS4pIwJC3zANBgkqhkiG9w0BAQsFADBBMQswCQYDVQQGEwJV\n' +
                            '...\n' +
                            '-----END CERTIFICATE-----',
                        display: {
                            show: {
                                'connection.useSelfSignedSsl': ['true']
                            }
                        }
                    },
                    {
                        label: 'Client key',
                        name: 'connection.key',
                        startVersion: MongoDBPluginVersions.V7,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.TEXT,
                        placeholder: '-----BEGIN RSA PRIVATE KEY-----\n' +
                            'BAoMBFRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCpvozN05Ou\n' +
                            '...\n' +
                            '-----END RSA PRIVATE KEY-----',
                        display: {
                            show: {
                                'connection.useSelfSignedSsl': ['true']
                            }
                        }
                    },
                    {
                        label: 'Client cert',
                        name: 'connection.cert',
                        startVersion: MongoDBPluginVersions.V7,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.TEXT,
                        placeholder: '-----BEGIN CERTIFICATE-----\n' +
                            'Ur2LYWdrVjqlS/wJyVIze15FMf7sgl+RINsLbQDLwS4pIwJC3zANBgkqhkiG9w0B\n' +
                            '...\n' +
                            '-----END CERTIFICATE-----',
                        display: {
                            show: {
                                'connection.useSelfSignedSsl': ['true']
                            }
                        }
                    }
                ]
            }
        ]
    },
    actionTemplate: {
        sections: [
            {
                name: 'main',
                items: [
                    {
                        label: 'Operation',
                        name: 'action',
                        startVersion: MongoDBPluginVersions.V1,
                        initialValue: MongoDBOperationType.find,
                        componentType: FormComponentType.DROPDOWN,
                        options: Object.values(MongoDBOperationType).map((op) => {
                            return { key: op, value: op, displayName: op };
                        }),
                        tooltip: {
                            markdownText: 'Operations supported by MongoDB. [Operation Docs](https://docs.mongodb.com/manual/core/transactions-operations/)'
                        },
                        showSearch: true
                    },
                    {
                        label: 'Collection',
                        name: 'resource',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: Object.values(MongoDBOperationType).reduce((acc, ele) => (ele !== MongoDBOperationType.listCollections ? acc.concat(ele) : acc), [])
                            }
                        },
                        tooltip: {
                            markdownText: 'Collection is a grouping of MongoDB documents. [Collection Docs](https://docs.mongodb.com/manual/core/databases-and-collections/#collections)'
                        }
                    },
                    {
                        label: 'Field',
                        name: 'field',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [MongoDBOperationType.distinct]
                            }
                        },
                        tooltip: {
                            markdownText: 'The field for which to return distinct values. [Distinct Docs](https://docs.mongodb.com/manual/reference/method/db.collection.distinct/)'
                        }
                    },
                    {
                        label: 'Pipeline',
                        name: 'pipeline',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON,
                        placeholder: `[
  { $match: { status: "active" } },
  { $group: { _id: "$cust_id", total: { $sum: "$amount" } } },
  { $sort: { total: -1 } }
]`,
                        display: {
                            show: {
                                action: [MongoDBOperationType.aggregate]
                            }
                        },
                        tooltip: {
                            markdownText: 'An aggregation pipeline consists of one or more stages that process documents. [Pipeline Docs](https://docs.mongodb.com/manual/core/aggregation-pipeline/)'
                        }
                    },
                    {
                        label: 'Query',
                        name: 'query',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON,
                        placeholder: `{ { $oid: '6161dc297f58812dd06ca190' }, qty: 5 }`,
                        display: {
                            show: {
                                action: [MongoDBOperationType.count, MongoDBOperationType.distinct, MongoDBOperationType.find, MongoDBOperationType.findOne]
                            }
                        },
                        tooltip: {
                            markdownText: 'Query used in MongoDB operations. [Query Docs](https://docs.mongodb.com/manual/tutorial/query-documents/)'
                        }
                    },
                    {
                        label: 'Projection',
                        name: 'projection',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON,
                        placeholder: `{ _id: 1, name: 0 }`,
                        display: {
                            show: {
                                action: [MongoDBOperationType.find, MongoDBOperationType.findOne]
                            }
                        },
                        tooltip: {
                            markdownText: 'Projection determines which fields are returned in the matching documents. [Projection Docs](https://docs.mongodb.com/manual/reference/method/db.collection.find/#std-label-method-find-projection)'
                        }
                    },
                    {
                        label: 'Sort by',
                        name: 'sortby',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON,
                        placeholder: `{ _id: 1, name: 1 }`,
                        display: {
                            show: {
                                action: [MongoDBOperationType.find]
                            }
                        },
                        tooltip: {
                            markdownText: 'Sort the results. [Sort Docs](https://docs.mongodb.com/manual/reference/method/cursor.sort/#mongodb-method-cursor.sort)'
                        }
                    },
                    {
                        label: 'Limit',
                        name: 'limit',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [MongoDBOperationType.find]
                            }
                        },
                        tooltip: {
                            markdownText: 'Specify the maximum number of documents the cursor will return. [Limit Docs](https://docs.mongodb.com/manual/reference/method/cursor.limit/)'
                        }
                    },
                    {
                        label: 'Skip',
                        name: 'skip',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.DYNAMIC_INPUT_TEXT,
                        display: {
                            show: {
                                action: [MongoDBOperationType.find]
                            }
                        },
                        tooltip: {
                            markdownText: 'Method on a cursor to control where MongoDB begins returning results. [Skip Docs](https://docs.mongodb.com/manual/reference/method/cursor.skip/)'
                        }
                    },
                    {
                        label: 'Document',
                        name: 'document',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON,
                        display: {
                            show: {
                                action: [MongoDBOperationType.insertOne, MongoDBOperationType.insertMany]
                            }
                        },
                        tooltip: {
                            markdownText: 'A document to insert into the collection. [Insert Docs](https://docs.mongodb.com/manual/reference/method/db.collection.insert/)'
                        }
                    },
                    {
                        label: 'Filter',
                        name: 'filter',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON,
                        placeholder: `{ { $oid: '6161dc297f58812dd06ca190' }, qty: 5 }`,
                        display: {
                            show: {
                                action: [
                                    MongoDBOperationType.deleteOne,
                                    MongoDBOperationType.deleteMany,
                                    MongoDBOperationType.listCollections,
                                    MongoDBOperationType.replaceOne,
                                    MongoDBOperationType.updateOne,
                                    MongoDBOperationType.updateMany
                                ]
                            }
                        },
                        tooltip: {
                            markdownText: 'The filter is a document that specifies the condition for matching the document to operate. You can use [Query Operators](https://docs.mongodb.com/manual/reference/operator/)'
                        }
                    },
                    {
                        label: 'Replacement',
                        name: 'replacement',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON,
                        display: {
                            show: {
                                action: [MongoDBOperationType.replaceOne]
                            }
                        },
                        tooltip: {
                            markdownText: 'The replacement document. [ReplaceOne Docs](https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/)'
                        }
                    },
                    {
                        label: 'Update',
                        name: 'update',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON,
                        placeholder: '{ $set: { status: "modified", comments: [ "$feedback1" ] } }',
                        display: {
                            show: {
                                action: [MongoDBOperationType.updateOne, MongoDBOperationType.updateMany]
                            }
                        },
                        tooltip: {
                            markdownText: 'The modifications to apply. [Update Docs](https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/)'
                        }
                    },
                    {
                        label: 'Options',
                        name: 'options',
                        startVersion: MongoDBPluginVersions.V1,
                        componentType: FormComponentType.CODE_EDITOR,
                        language: EditorLanguage.JSON,
                        display: {
                            show: {
                                action: [
                                    MongoDBOperationType.aggregate,
                                    MongoDBOperationType.count,
                                    MongoDBOperationType.distinct,
                                    MongoDBOperationType.replaceOne,
                                    MongoDBOperationType.updateOne,
                                    MongoDBOperationType.updateMany
                                ]
                            }
                        }
                        //TODO: Options can be different on different operation type. Make this dynamic based on selected operation.
                        // One field (e.g., tooltip, placebolder...) can be dependent on the value of a different field, maybe create a new prop for this cause.
                    }
                ]
            }
        ]
    }
};
//# sourceMappingURL=mongodb.js.map