/**
 * 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 { computed, makeObservable, observable, override } from 'mobx';
import { ModelEmbeddedData, ModelInstanceData, ExternalFormatData, DataElementReference, ModelStoreData, RelationElementsData, } from '../../../graph/metamodel/pure/data/EmbeddedData.js';
import { RelationalCSVData, } from '../../../graph/metamodel/pure/data/RelationalCSVData.js';
import { observe_Abstract_PackageableElement, skipObserved, skipObservedWithContext, } from './CoreObserverHelper.js';
import { observe_StereotypeReference, observe_TaggedValue, } from './DomainObserverHelper.js';
import { INTERNAL__UnknownEmbeddedData } from '../../../graph/metamodel/pure/data/INTERNAL__UnknownEmbeddedData.js';
export const observe_ExternalFormatData = skipObserved((metamodel) => {
    makeObservable(metamodel, {
        contentType: observable,
        data: observable,
        hashCode: computed,
    });
    return metamodel;
});
export const observe_DataElementReference = skipObserved((metamodel) => {
    makeObservable(metamodel, {
        dataElement: observable,
        hashCode: computed,
    });
    return metamodel;
});
const observe_ModelEmbeddedData = skipObservedWithContext((metamodel, context) => {
    makeObservable(metamodel, {
        model: observable,
        data: observable,
        hashCode: computed,
    });
    observe_EmbeddedData(metamodel.data, context);
    return metamodel;
});
export const observe_ModelInstanceData = skipObservedWithContext((metamodel, context) => {
    makeObservable(metamodel, {
        model: observable,
        instances: observable,
        hashCode: computed,
    });
    return metamodel;
});
export const observe_ModelData = skipObservedWithContext((metamodel, context) => {
    if (metamodel instanceof ModelEmbeddedData) {
        observe_ModelEmbeddedData(metamodel, context);
    }
    else if (metamodel instanceof ModelInstanceData) {
        observe_ModelInstanceData(metamodel, context);
    }
    return metamodel;
});
export const observe_ModelStoreData = skipObservedWithContext((metamodel, context) => {
    makeObservable(metamodel, {
        modelData: observable,
        hashCode: computed,
    });
    metamodel.modelData?.forEach((e) => {
        observe_ModelData(e, context);
    });
    return metamodel;
});
export const observe_RelationalDataTable = skipObserved((metamodel) => {
    makeObservable(metamodel, {
        values: observable,
        table: observable,
        schema: observable,
        hashCode: computed,
    });
    return metamodel;
});
const observe_RelationalCSVData = skipObserved((metamodel) => {
    makeObservable(metamodel, {
        tables: observable,
        hashCode: computed,
    });
    metamodel.tables.forEach(observe_RelationalDataTable);
    return metamodel;
});
export const observe_RelationRowTestData = skipObserved((metamodel) => {
    makeObservable(metamodel, {
        values: observable,
    });
    return metamodel;
});
export const observe_RelationElement = skipObserved((metamodel) => {
    makeObservable(metamodel, {
        paths: observable,
        columns: observable,
        rows: observable,
        hashCode: computed,
    });
    metamodel.rows.forEach(observe_RelationRowTestData);
    return metamodel;
});
export const observe_RelationElementsData = skipObserved((metamodel) => {
    makeObservable(metamodel, {
        hashCode: computed,
    });
    metamodel.relationElements.forEach(observe_RelationElement);
    return metamodel;
});
export const observe_INTERNAL__UnknownEmbeddedData = skipObserved((metamodel) => {
    makeObservable(metamodel, {
        content: observable.ref,
    });
    return metamodel;
});
export function observe_EmbeddedData(metamodel, context) {
    if (metamodel instanceof INTERNAL__UnknownEmbeddedData) {
        return observe_INTERNAL__UnknownEmbeddedData(metamodel);
    }
    else if (metamodel instanceof DataElementReference) {
        return observe_DataElementReference(metamodel);
    }
    else if (metamodel instanceof ExternalFormatData) {
        return observe_ExternalFormatData(metamodel);
    }
    else if (metamodel instanceof ModelStoreData) {
        return observe_ModelStoreData(metamodel, context);
    }
    else if (metamodel instanceof RelationalCSVData) {
        return observe_RelationalCSVData(metamodel);
    }
    else if (metamodel instanceof RelationElementsData) {
        return observe_RelationElementsData(metamodel);
    }
    const extraEmbeddedDataObservers = context.plugins.flatMap((plugin) => plugin.getExtraEmbeddedDataObservers?.() ?? []);
    for (const observer of extraEmbeddedDataObservers) {
        const observedEmbeddedData = observer(metamodel, context);
        if (observedEmbeddedData) {
            return observedEmbeddedData;
        }
    }
    return metamodel;
}
export const observe_DataElement = skipObservedWithContext((metamodel, context) => {
    observe_Abstract_PackageableElement(metamodel);
    makeObservable(metamodel, {
        stereotypes: observable,
        taggedValues: observable,
        data: observable,
        _elementHashCode: override,
    });
    metamodel.stereotypes.forEach(observe_StereotypeReference);
    metamodel.taggedValues.forEach(observe_TaggedValue);
    observe_EmbeddedData(metamodel.data, context);
    return metamodel;
});
//# sourceMappingURL=DSL_Data_ObserverHelper.js.map