"use strict";
/*
 *  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *  SPDX-License-Identifier: Apache-2.0
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvTypeConfigService = void 0;
const swb_app_1 = require("@aws/swb-app");
const workbench_core_base_1 = require("@aws/workbench-core-base");
class EnvTypeConfigService {
    constructor(envTypeConfigService, metadataService) {
        this._envTypeConfigService = envTypeConfigService;
        this._metadataService = metadataService;
    }
    async getEnvTypeConfig(request) {
        return await this._envTypeConfigService.getEnvironmentTypeConfig(request.envTypeId, request.envTypeConfigId);
    }
    async listEnvTypeConfigs(request) {
        return await this._envTypeConfigService.listEnvironmentTypeConfigs(request);
    }
    async createEnvTypeConfig(request) {
        return await this._envTypeConfigService.createNewEnvironmentTypeConfig(request);
    }
    async updateEnvTypeConfig(request) {
        return await this._envTypeConfigService.updateEnvironmentTypeConfig(request);
    }
    async deleteEnvTypeConfig(request) {
        await this._validateAssociations(request.envTypeId, request.envTypeConfigId);
        return await this._envTypeConfigService.softDeleteEnvironmentTypeConfig(request);
    }
    async _validateAssociations(envTypeId, envTypeConfigId) {
        var _a;
        const composedType = `${workbench_core_base_1.resourceTypeToKey.envType}#${envTypeId}${workbench_core_base_1.resourceTypeToKey.envTypeConfig}`;
        const relationshipIds = await this._metadataService.listDependentMetadata(composedType, envTypeConfigId, workbench_core_base_1.resourceTypeToKey.project, workbench_core_base_1.RelationshipDDBItemParser);
        if ((_a = relationshipIds === null || relationshipIds === void 0 ? void 0 : relationshipIds.data) === null || _a === void 0 ? void 0 : _a.length) {
            throw new swb_app_1.ConflictError(`There are projects associated with Workspace configuration. Please dissasociate projects from configuration before deleting.`);
        }
    }
}
exports.EnvTypeConfigService = EnvTypeConfigService;
//# sourceMappingURL=envTypeConfigService.js.map