/**
 * Copyright (c) 2020-present, Goldman Sachs
 *
 * 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.
 */
import { PackageableElementReference, FileGenerationSpecification, GenerationTreeNode, PackageableElementExplicitReference, ModelGenerationSpecification, observe_PackageableElementReference, observe_FileGenerationSpecification, observe_GenerationTreeNode, observe_ConfigurationProperty, } from '@finos/legend-graph';
import { addUniqueEntry, changeEntry, deleteEntry, UnsupportedOperationError, } from '@finos/legend-shared';
import { action } from 'mobx';
// --------------------------------------------- File Generation -------------------------------------
export const configurationProperty_setValue = action((cp, value) => {
    cp.value = value;
});
export const configurationProperty_addConfigurationProperty = action((configurationProperties, cp) => {
    addUniqueEntry(configurationProperties, observe_ConfigurationProperty(cp));
});
export const fileGeneration_setType = action((fg, value) => {
    fg.type = value;
});
export const fileGeneration_setGenerationOutputPath = action((fg, val) => {
    fg.generationOutputPath = val;
});
export const fileGeneration_setScopeElements = action((fg, value) => {
    fg.scopeElements = value.map((v) => v instanceof PackageableElementReference
        ? observe_PackageableElementReference(v)
        : v);
});
export const fileGeneration_addScopeElement = action((fg, value) => {
    addUniqueEntry(fg.scopeElements, value instanceof PackageableElementReference
        ? observe_PackageableElementReference(value)
        : value);
});
export const fileGeneration_deleteScopeElement = action((fg, value) => {
    deleteEntry(fg.scopeElements, value);
});
export const fileGeneration_changeScopeElement = action((fg, oldValue, newValue) => {
    changeEntry(fg.scopeElements, oldValue, newValue instanceof PackageableElementReference
        ? observe_PackageableElementReference(newValue)
        : newValue);
});
// -------------------------------- Generation Specification -------------------------------------
export const generationSpecification_addNode = action((genSpec, value) => {
    addUniqueEntry(genSpec.generationNodes, observe_GenerationTreeNode(value));
});
export const generationSpecification_addFileGeneration = action((genSpec, value) => {
    addUniqueEntry(genSpec.fileGenerations, observe_PackageableElementReference(PackageableElementExplicitReference.create(observe_FileGenerationSpecification(value))));
});
export const createObservableFileGeneration = action(() => observe_FileGenerationSpecification(new FileGenerationSpecification('')));
export const generationSpecification_deleteFileGeneration = action((genSpec, value) => {
    deleteEntry(genSpec.fileGenerations, value);
});
export const generationSpecification_setId = action((treeNode, val) => {
    treeNode.id = val;
});
export const generationSpecification_deleteGenerationNode = action((genSpec, value) => {
    deleteEntry(genSpec.generationNodes, value);
});
// NOTE as of now the generation specification only supports model generation elements i.e elements that generate another graph compatabile with the current graph.
export const generationSpecification_addGenerationElement = action((genSpec, element) => {
    if (!(element instanceof ModelGenerationSpecification ||
        element instanceof FileGenerationSpecification)) {
        throw new UnsupportedOperationError(`Can't add generation element: only model generation elements can be added to the generation specification`, element);
    }
    if (element instanceof FileGenerationSpecification) {
        generationSpecification_addFileGeneration(genSpec, element);
    }
    else {
        generationSpecification_addNode(genSpec, observe_GenerationTreeNode(new GenerationTreeNode(PackageableElementExplicitReference.create(element))));
    }
});
//# sourceMappingURL=DSL_Generation_GraphModifierHelper.js.map