"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormatterService = void 0;
/*
 *
 * Copyright 2018-present NEM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
const chalk_1 = require("chalk");
/**
 * Formatter service.
 */
class FormatterService {
    /**
     * Handle sucess string.
     * @param {string} value - value to format.
     * @returns {string}
     */
    static success(value) {
        return '\n' + chalk_1.default.green.bold('SUCCESS') + ' ' + value;
    }
    /**
     * Handle informative string.
     * @param {string} value - value to format.
     * @returns {string}
     */
    static info(value) {
        return '\n' + chalk_1.default.blue.bold('TIP') + ' ' + value;
    }
    /**
     * Handle sucess string.
     * @param {string} value - value to format.
     * @returns {string}
     */
    static title(value) {
        return '\n' + chalk_1.default.cyan(value);
    }
    /**
     * Handle error thrown by an HTTP call.
     * @param {any} value - value to format.
     * @returns {string}
     */
    static error(value) {
        let result = '\n' + chalk_1.default.red.bold('ERR') + ' ';
        if (value instanceof Object && 'message' in value) {
            try {
                const message = JSON.parse(value.message);
                if ('valueorDetails' in message && 'statusMessage' in message.valueorDetails) {
                    result += message.valueorDetails.statusMessage;
                }
                else {
                    result += value.message;
                }
            }
            catch (e) {
                result += value.message;
            }
        }
        else {
            result += value;
        }
        return result;
    }
}
exports.FormatterService = FormatterService;
