"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Analytics = require("../features/analytics/Analytics");
const compactd_models_1 = require("compactd-models");
const storyboard_1 = require("storyboard");
exports.default = (app) => {
    app.post('/api/reports/library/:artist/:album/:number/:track/:type', (req, res) => {
        const { artist, album, track, type, number } = req.params;
        const id = compactd_models_1.trackURI({ artist, album, number, name: track });
        storyboard_1.mainStory.debug('analytics', `Reported ${type} for ${id}`);
        Analytics.report(type, id).then((doc) => {
            res.status(201).send(doc);
        }).catch((err) => {
            res.send({ ok: false, error: 'An error has occured while creating a report' });
            storyboard_1.mainStory.error('analytics', 'An error occured', { attach: err });
        });
    });
    app.get('/api/reports/tracks/top', (req, res) => {
        Analytics.getTopTracks(req.query.limit).then((docs) => {
            res.status(200).send(docs);
        }).catch((err) => {
            res.send({ error: 'An error has occured while reducing reports' });
            storyboard_1.mainStory.error('analytics', 'An error occured', { attach: err });
        });
    });
};
//# sourceMappingURL=analytics.js.map