"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorReportingCommand = exports.UsageReportingCommand = exports.AnalyticsCommandParameter = void 0;
const yok_1 = require("../yok");
class AnalyticsCommandParameter {
    constructor($errors) {
        this.$errors = $errors;
        this.mandatory = false;
    }
    async validate(validationValue) {
        const val = validationValue || "";
        switch (val.toLowerCase()) {
            case "enable":
            case "disable":
            case "status":
            case "":
                return true;
            default:
                this.$errors.failWithHelp(`The value '${validationValue}' is not valid. Valid values are 'enable', 'disable' and 'status'.`);
        }
    }
}
exports.AnalyticsCommandParameter = AnalyticsCommandParameter;
class AnalyticsCommand {
    constructor($analyticsService, $logger, $errors, $options, settingName, humanReadableSettingName) {
        this.$analyticsService = $analyticsService;
        this.$logger = $logger;
        this.$errors = $errors;
        this.$options = $options;
        this.settingName = settingName;
        this.humanReadableSettingName = humanReadableSettingName;
        this.allowedParameters = [new AnalyticsCommandParameter(this.$errors)];
        this.disableAnalytics = true;
    }
    async execute(args) {
        const arg = args[0] || "";
        switch (arg.toLowerCase()) {
            case "enable":
                await this.$analyticsService.setStatus(this.settingName, true);
                this.$logger.info(`${this.humanReadableSettingName} is now enabled.`);
                break;
            case "disable":
                await this.$analyticsService.setStatus(this.settingName, false);
                this.$logger.info(`${this.humanReadableSettingName} is now disabled.`);
                break;
            case "status":
            case "":
                this.$logger.info(await this.$analyticsService.getStatusMessage(this.settingName, this.$options.json, this.humanReadableSettingName));
                break;
        }
    }
}
class UsageReportingCommand extends AnalyticsCommand {
    constructor($analyticsService, $logger, $errors, $options, $staticConfig) {
        super($analyticsService, $logger, $errors, $options, $staticConfig.TRACK_FEATURE_USAGE_SETTING_NAME, "Usage reporting");
        this.$analyticsService = $analyticsService;
    }
}
exports.UsageReportingCommand = UsageReportingCommand;
yok_1.injector.registerCommand("usage-reporting", UsageReportingCommand);
class ErrorReportingCommand extends AnalyticsCommand {
    constructor($analyticsService, $logger, $errors, $options, $staticConfig) {
        super($analyticsService, $logger, $errors, $options, $staticConfig.ERROR_REPORT_SETTING_NAME, "Error reporting");
        this.$analyticsService = $analyticsService;
    }
}
exports.ErrorReportingCommand = ErrorReportingCommand;
yok_1.injector.registerCommand("error-reporting", ErrorReportingCommand);
