/**
 * 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 { guaranteeType, UnsupportedOperationError } from '@finos/legend-shared';
import { ExternalFormatData } from '../../../../../../../../graph/metamodel/pure/data/EmbeddedData.js';
import { EqualTo } from '../../../../../../../../graph/metamodel/pure/test/assertion/EqualTo.js';
import { EqualToJson } from '../../../../../../../../graph/metamodel/pure/test/assertion/EqualToJson.js';
import { EqualToTDS } from '../../../../../../../../graph/metamodel/pure/test/assertion/EqualToTDS.js';
import { V1_MappingTestSuite } from '../../../../model/packageableElements/mapping/V1_MappingTestSuite.js';
import { V1_ServiceTestSuite } from '../../../../model/packageableElements/service/V1_ServiceTestSuite.js';
import { V1_EqualTo } from '../../../../model/test/assertion/V1_EqualTo.js';
import { V1_EqualToJson } from '../../../../model/test/assertion/V1_EqualToJson.js';
import { V1_EqualToTDS } from '../../../../model/test/assertion/V1_EqualToTDS.js';
import { V1_buildEmbeddedData } from './V1_DataElementBuilderHelper.js';
import { V1_buildMappingTestSuite } from './V1_MappingBuilderHelper.js';
import { V1_buildServiceTestSuite } from './V1_ServiceBuilderHelper.js';
const V1_buildEqualTo = (element, parentTest) => {
    const equalTo = new EqualTo();
    equalTo.id = element.id;
    equalTo.parentTest = parentTest;
    equalTo.expected = element.expected;
    return equalTo;
};
export const V1_buildEqualToJson = (element, parentTest, context) => {
    const equalToJson = new EqualToJson();
    equalToJson.id = element.id;
    equalToJson.parentTest = parentTest;
    equalToJson.expected = guaranteeType(V1_buildEmbeddedData(element.expected, context), ExternalFormatData);
    return equalToJson;
};
const buildEqualToTDS = (element, parentTest, context) => {
    const equalToTDS = new EqualToTDS();
    equalToTDS.id = element.id;
    equalToTDS.parentTest = parentTest;
    equalToTDS.expected = guaranteeType(V1_buildEmbeddedData(element.expected, context), ExternalFormatData);
    return equalToTDS;
};
export const V1_buildTestAssertion = (value, parentTest, context) => {
    if (value instanceof V1_EqualTo) {
        return V1_buildEqualTo(value, parentTest);
    }
    else if (value instanceof V1_EqualToJson) {
        return V1_buildEqualToJson(value, parentTest, context);
    }
    else if (value instanceof V1_EqualToTDS) {
        return buildEqualToTDS(value, parentTest, context);
    }
    throw new UnsupportedOperationError(`Can't build test assertion`, value);
};
export const V1_buildAtomicTest = (value, context) => {
    const extraAtomicTestBuilder = context.extensions.plugins.flatMap((plugin) => plugin.V1_getExtraAtomicTestBuilders?.() ?? []);
    for (const builder of extraAtomicTestBuilder) {
        const metamodel = builder(value, context);
        if (metamodel) {
            return metamodel;
        }
    }
    throw new UnsupportedOperationError(`Can't build AtomicTest: no compatible builder available from plugins`, value);
};
export const V1_buildTestSuite = (parent, value, context) => {
    let suite;
    if (value instanceof V1_ServiceTestSuite) {
        suite = V1_buildServiceTestSuite(value, context);
    }
    else if (value instanceof V1_MappingTestSuite) {
        suite = V1_buildMappingTestSuite(value, context);
    }
    if (suite) {
        suite.__parent = parent;
        return suite;
    }
    throw new UnsupportedOperationError(`Can't build test suite`, value);
};
//# sourceMappingURL=V1_TestBuilderHelper.js.map