"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const os_1 = require("os");
class AnalyticsLoggingService {
    constructor($fs, logFile) {
        this.$fs = $fs;
        this.logFile = logFile;
    }
    logData(analyticsLoggingMessage) {
        if (this.logFile && analyticsLoggingMessage && analyticsLoggingMessage.message) {
            analyticsLoggingMessage.type = analyticsLoggingMessage.type || "Info";
            const formattedDate = this.getFormattedDate();
            this.$fs.appendFile(this.logFile, `[${formattedDate}] [${analyticsLoggingMessage.type}] ${analyticsLoggingMessage.message}${os_1.EOL}`);
        }
    }
    getFormattedDate() {
        const currentDate = new Date();
        const year = currentDate.getFullYear();
        const month = this.getFormattedDateComponent((currentDate.getMonth() + 1));
        const day = this.getFormattedDateComponent(currentDate.getDate());
        const hour = this.getFormattedDateComponent(currentDate.getHours());
        const minutes = this.getFormattedDateComponent(currentDate.getMinutes());
        const seconds = this.getFormattedDateComponent(currentDate.getSeconds());
        const milliseconds = this.getFormattedMilliseconds(currentDate);
        return `${[year, month, day].join('-')} ${[hour, minutes, seconds].join(":")}.${milliseconds}`;
    }
    getFormattedDateComponent(component) {
        const stringComponent = component.toString();
        return stringComponent.length === 1 ? `0${stringComponent}` : stringComponent;
    }
    getFormattedMilliseconds(date) {
        let milliseconds = date.getMilliseconds().toString();
        while (milliseconds.length < 3) {
            milliseconds = `0${milliseconds}`;
        }
        return milliseconds;
    }
}
exports.AnalyticsLoggingService = AnalyticsLoggingService;
