"use strict";
/*
 * Copyright 2020 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.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.BootstrapService = void 0;
const BootstrapUtils_1 = require("./BootstrapUtils");
const ComposeService_1 = require("./ComposeService");
const ConfigService_1 = require("./ConfigService");
const LinkService_1 = require("./LinkService");
const ReportService_1 = require("./ReportService");
const RewardProgramService_1 = require("./RewardProgramService");
const RunService_1 = require("./RunService");
/**
 * Main entry point for API integration.
 */
class BootstrapService {
    constructor(root = BootstrapUtils_1.BootstrapUtils.DEFAULT_ROOT_FOLDER) {
        this.root = root;
    }
    /**
     * It generates the configuration and nemesis for the provided preset
     *
     * @param config the params of the config command.
     */
    async config(config = ConfigService_1.ConfigService.defaultParams) {
        return new ConfigService_1.ConfigService(this.root, config).run();
    }
    /**
     * It resolves the preset used for preventive configuration.
     *
     * @param config the params of the config command.
     */
    resolveConfigPreset(config = ConfigService_1.ConfigService.defaultParams) {
        return new ConfigService_1.ConfigService(this.root, config).resolveConfigPreset(false);
    }
    /**
     * It generates the docker-compose.yaml file from the previously generated configuration.
     *
     * The config method/command needs to be called before this method
     *
     * @param config the params of the compose command.
     * @param passedPresetData the created preset if you know it, otherwise will load the latest one resolved from the target folder.
     * @param passedAddresses the created addresses if you know if, otherwise will load the latest one resolved form the target folder.
     */
    compose(config = ComposeService_1.ComposeService.defaultParams, passedPresetData, passedAddresses) {
        return new ComposeService_1.ComposeService(this.root, config).run(passedPresetData, passedAddresses);
    }
    /**
     * It calls a running server announcing all the node transactions like VRF and Voting.
     *
     * This command is useful to link the nodes keys to an existing running network like testnet.
     *
     * @param config the params passed
     * @param passedPresetData  the created preset if you know it, otherwise will load the latest one resolved from the target folder.
     * @param passedAddresses  the created addresses if you know it, otherwise will load the latest one resolved from the target folder.
     */
    async link(config = LinkService_1.LinkService.defaultParams, passedPresetData, passedAddresses) {
        await new LinkService_1.LinkService(config).run(passedPresetData, passedAddresses);
    }
    /**
     * It calls a running service announcing the registration of the nodes to the supernode rewards program.
     *
     * @param config the params passed
     * @param passedPresetData  the created preset if you know it, otherwise will load the latest one resolved from the target folder.
     * @param passedAddresses  the created addresses if you know it, otherwise will load the latest one resolved from the target folder.
     */
    async enrollRewardProgram(config = RewardProgramService_1.RewardProgramService.defaultParams, passedPresetData, passedAddresses) {
        await new RewardProgramService_1.RewardProgramService(config).enroll(passedPresetData, passedAddresses);
    }
    /**
     * It generates reStructuredText (.rst) reports describing the configuration of each node.
     *
     * The config method/command needs to be called before this method
     *
     * @param config the params of the report command.
     * @param passedPresetData the created preset if you know if, otherwise will load the latest one resolved from the target folder.
     * @return the paths of the created reports.
     */
    async report(config = ReportService_1.ReportService.defaultParams, passedPresetData) {
        return await new ReportService_1.ReportService(this.root, config).run(passedPresetData);
    }
    /**
     * It boots the network via docker using the generated docker-compose.yml file and configuration
     *
     * The config and compose methods/commands need to be called before this method.
     *
     * This is just a wrapper for docker-compose up bash call.
     *
     * @param config the params of the run command.
     */
    async run(config = RunService_1.RunService.defaultParams) {
        await new RunService_1.RunService(config).run();
    }
    /**
     * It resets the data keeping generated configuration, block 1, certificates and keys.
     *
     * @param config the params of the clean command.
     */
    async resetData(config = { target: RunService_1.RunService.defaultParams.target }) {
        await new RunService_1.RunService(config).resetData();
    }
    /**
     * It checks if the health of the running services is ok.
     *
     * @param config the params of the clean command.
     */
    async healthCheck(config = { target: RunService_1.RunService.defaultParams.target }) {
        await new RunService_1.RunService(config).healthCheck();
    }
    /**
     * This method aggregates config, compose and run all in one.
     *
     * @param config the aggregated params in order to run all the sub commands.
     */
    async start(config) {
        const configResult = await this.config(config);
        await this.compose(config, configResult.presetData);
        await this.run(config);
        return configResult;
    }
    /**
     * It stops the docker-compose network if running.
     *
     * This is just a wrapper for docker-compose down bash call.
     *
     * @param config the params necessary to detect and stop the network.
     */
    async stop(config = RunService_1.RunService.defaultParams) {
        await new RunService_1.RunService(config).stop();
    }
}
exports.BootstrapService = BootstrapService;
