"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadLogPublications = loadLogPublications;
var simpl_schema_1 = require("simpl-schema");
var log_method_latency_collection_1 = require("../collections/log-method-latency.collection");
var log_collection_1 = require("../collections/log.collection");
function loadLogPublications(subscriptionManager) {
    subscriptionManager.publications({
        logsWithType: {
            function: function (type) {
                if (type === 'all') {
                    return log_collection_1.Logs.find({}, { sort: { createdAt: -1 } });
                }
                return log_collection_1.Logs.find({ type: type }, { sort: { createdAt: -1 } });
            },
            check: new simpl_schema_1.default({
                type: {
                    type: String
                }
            }),
            collections: ['logs']
        },
        logsWithTypes: {
            function: function (types) {
                return log_collection_1.Logs.find({ type: { $in: types } }, { sort: { createdAt: -1 } });
            },
            check: new simpl_schema_1.default({
                types: {
                    type: Array
                },
                'types.$': {
                    type: String
                }
            }),
            collections: ['logs']
        },
        logsWithIdDocument: {
            function: function (id_document) {
                return log_collection_1.Logs.find({ id_document: id_document }, { sort: { createdAt: -1 } });
            },
            check: new simpl_schema_1.default({
                id_document: {
                    type: String
                }
            }),
            collections: ['logs']
        },
        logsWithMethod: {
            function: function (method) {
                return log_collection_1.Logs.find({ method: method }, { sort: { createdAt: -1 } });
            },
            check: new simpl_schema_1.default({
                method: {
                    type: String
                }
            }),
            collections: ['logs']
        },
        logsWithRoute: {
            function: function (route) {
                return log_collection_1.Logs.find({ route: route }, { sort: { createdAt: -1 } });
            },
            check: new simpl_schema_1.default({
                route: {
                    type: String
                }
            }),
            collections: ['logs']
        },
        logsWithCollection: {
            function: function (collection) {
                return log_collection_1.Logs.find({ collection: collection }, { sort: { createdAt: -1 } });
            },
            check: new simpl_schema_1.default({
                collection: {
                    type: String
                }
            }),
            collections: ['logs']
        },
        methodlatencies: {
            function: function () {
                return log_method_latency_collection_1.LogMethodLatencies.find({}, { sort: { date_start: -1 } });
            },
            collections: ['log-method-latencies'],
        },
        // superadminAPM: {
        // 	check: new SimpleSchema({
        // 		date_start: {
        // 			type: Date
        // 		},
        // 		date_end: {
        // 			type: Date
        // 		}
        // 	}),
        // 	function: function(date_start: Date, date_end: Date) {
        // 		return new Promise(async (resolve, reject) => {
        // 			let latencies = await LogMethodLatencies.aggregate([
        // 				{
        // 					$match: {
        // 						$and: [
        // 							{
        // 								createdAt: {$gte: date_start}
        // 							},
        // 							{
        // 								createdAt: {$lte: date_end}
        // 							}
        // 						]
        // 					}
        // 				},
        // 				{
        // 					$group: {
        // 						_id: '$method',
        // 						method: {$first: '$method'},
        // 						count: {$sum: 1},
        // 						latency_min: {$min: '$latency_ms'},
        // 						latency_avg: {$avg: '$latency_ms'},
        // 						latency_max: {$max: '$latency_ms'}
        // 					}
        // 				},
        // 				{
        // 					$sort: {
        // 						latency_avg: -1
        // 					}
        // 				}
        // 			]);
        // 			let subscriptions = await LogSubscriptions.aggregate([
        // 				{
        // 					$match: {
        // 						$and: [
        // 							{
        // 								createdAt: {$gte: date_start}
        // 							},
        // 							{
        // 								createdAt: {$lte: date_end}
        // 							}
        // 						]
        // 					}
        // 				},
        // 				{
        // 					$group: {
        // 						_id: '$subscription',
        // 						subscription: {$first: '$subscription'},
        // 						count: {$sum: 1}
        // 					}
        // 				},
        // 				{
        // 					$sort: {
        // 						count: -1
        // 					}
        // 				}
        // 			]);
        // 			resolve({
        // 				methods: latencies,
        // 				subscriptions: subscriptions
        // 			});
        // 		});
        // 	},
        // 	collections: ['log-method-latencies', 'log-subscriptions'],
        // }
    });
}

//# sourceMappingURL=logs.js.map
