/**
 * 统计。
 */
"use strict";
var EventEmitter = require("events").EventEmitter;
var util = require("util");

var statsRepo = require("../repository/stats.msg.repo.js");
var log = require("../util/log.js");
var modelUtil = require('../util/modelUtil');

var MODEL_EVENTS = require('../include/commons').MODEL_EVENTS;

function StatsMessage() {
    // call the super constructor to initialize `this`
    EventEmitter.call(this);

    log.info("Construct StatsMessage.");
}

/**
 * 获取应用角标数，基于消息数量。
 * @param userId
 */
StatsMessage.prototype.getBadgeNumber = function(userId){
    var self = this;
    statsRepo.getBadgeNumber(userId, function (err, result) {
        if (err) {
            modelUtil.emitDbError(this, "Get badge number failed: ", err);
            return;
        }

        var data = {userId: userId, badge: result};
        self.emit(MODEL_EVENTS.OK, data);
    });
};

// This class inherits from EventEmitter and expose class
util.inherits(StatsMessage, EventEmitter);
module.exports = StatsMessage;