"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProfileService = 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 hdProfile_model_1 = require("../models/hdProfile.model");
const ledgerProfile_model_1 = require("../models/ledgerProfile.model");
const privateKeyProfile_model_1 = require("../models/privateKeyProfile.model");
/**
 * Profile service
 */
class ProfileService {
    /**
     * Constructor
     * @param {ProfileRepository} profileRepository
     */
    constructor(profileRepository) {
        this.profileRepository = profileRepository;
    }
    /**
     * Find profile by name.
     * @param {string} name - Profile name.
     * @returns {Profile}
     */
    findProfileNamed(name) {
        return this.profileRepository.find(name);
    }
    /**
     * Gets all profiles.
     * @returns {Profile[]}
     */
    findAllProfiles() {
        return this.profileRepository.all();
    }
    /**
     * Sets a profile as the default one.
     * @param {string} name - Profile name.
     */
    setDefaultProfile(name) {
        this.profileRepository.setDefault(name);
    }
    /**
     * Gets the profile set as default.
     * @returns {Profile}
     */
    getDefaultProfile() {
        return this.profileRepository.getDefaultProfile();
    }
    /**
     * Creates and save a new profile
     * @param {ProfileCreation} args
     * @returns {Profile}
     */
    createNewProfile(args) {
        const profile = 'mnemonic' in args ? hdProfile_model_1.HdProfile.create(args) : 'path' in args ? ledgerProfile_model_1.LedgerProfile.create(args) : privateKeyProfile_model_1.PrivateKeyProfile.create(args);
        this.profileRepository.save(profile);
        return profile;
    }
}
exports.ProfileService = ProfileService;
