/**
 * 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 { deserializeMap, optionalCustomList, optionalCustomUsingModelSchema, SerializationFactory, UnsupportedOperationError, usingConstantValueSchema, usingModelSchema, } from '@finos/legend-shared';
import { createModelSchema, custom, deserialize, list, object, optional, primitive, serialize, SKIP, } from 'serializr';
import { V1_deserializeGenericType, V1_genericTypeModelSchema, } from '../../transformation/pureProtocol/serializationHelpers/V1_TypeSerializationHelper.js';
import { V1_relationElementModelSchema } from '../../transformation/pureProtocol/serializationHelpers/V1_DataElementSerializationHelper.js';
import { V1_pureModelContextDataPropSchema } from '../../transformation/pureProtocol/V1_PureProtocolSerialization.js';
import { V1_MappedEntity } from '../../engine/analytics/V1_MappingModelCoverageAnalysis.js';
import { V1_multiplicityModelSchema } from '../../transformation/pureProtocol/serializationHelpers/V1_CoreSerializationHelper.js';
export var V1_DataProductTypeEnum;
(function (V1_DataProductTypeEnum) {
    V1_DataProductTypeEnum["INTERNAL"] = "internalDataProductType";
    V1_DataProductTypeEnum["EXTERNAL"] = "externalDataProductType";
})(V1_DataProductTypeEnum || (V1_DataProductTypeEnum = {}));
export var V1_ResourceBuilderType;
(function (V1_ResourceBuilderType) {
    V1_ResourceBuilderType["DATABASE_DDL"] = "databaseDDL";
    V1_ResourceBuilderType["FUNCTION_ACCESS_POINT"] = "functionAccessPoint";
})(V1_ResourceBuilderType || (V1_ResourceBuilderType = {}));
export var V1_ExecutableInfoType;
(function (V1_ExecutableInfoType) {
    V1_ExecutableInfoType["TEMPLATE"] = "templateExecutableInfo";
    V1_ExecutableInfoType["FUNCTION_POINTER"] = "functionPointerExecutableInfo";
    V1_ExecutableInfoType["SERVICE"] = "service";
    V1_ExecutableInfoType["MULTI_EXECUTION_SERVICE"] = "multiExecutionService";
})(V1_ExecutableInfoType || (V1_ExecutableInfoType = {}));
export var V1_ExecutableResultType;
(function (V1_ExecutableResultType) {
    V1_ExecutableResultType["TDS"] = "tds";
    V1_ExecutableResultType["RELATION"] = "relation";
})(V1_ExecutableResultType || (V1_ExecutableResultType = {}));
export var V1_DatabaseDDLImplementationType;
(function (V1_DatabaseDDLImplementationType) {
    V1_DatabaseDDLImplementationType["VIEW"] = "VIEW";
    V1_DatabaseDDLImplementationType["TABLE"] = "TABLE";
    V1_DatabaseDDLImplementationType["PROCEDURE"] = "PROCEDURE";
})(V1_DatabaseDDLImplementationType || (V1_DatabaseDDLImplementationType = {}));
export class V1_Artifact_DataProductType {
}
export class V1_Artifact_ExternalDataProductType extends V1_Artifact_DataProductType {
    link;
    static serialization = new SerializationFactory(createModelSchema(V1_Artifact_ExternalDataProductType, {
        _type: usingConstantValueSchema(V1_DataProductTypeEnum.EXTERNAL),
        link: optional(primitive()),
    }));
}
export class V1_Artifact_InternalDataProductType extends V1_Artifact_DataProductType {
    static serialization = new SerializationFactory(createModelSchema(V1_Artifact_InternalDataProductType, {
        _type: usingConstantValueSchema(V1_DataProductTypeEnum.INTERNAL),
    }));
}
export const V1_serializeDataProductType = (DataProductType) => {
    if (DataProductType instanceof V1_Artifact_ExternalDataProductType) {
        return V1_Artifact_ExternalDataProductType.serialization.toJson(DataProductType);
    }
    else if (DataProductType instanceof V1_Artifact_InternalDataProductType) {
        return V1_Artifact_InternalDataProductType.serialization.toJson(DataProductType);
    }
    throw new UnsupportedOperationError();
};
export const V1_deserializeDataProductType = (json) => {
    switch (json._type) {
        case V1_DataProductTypeEnum.EXTERNAL:
            return V1_Artifact_ExternalDataProductType.serialization.fromJson(json);
        case V1_DataProductTypeEnum.INTERNAL:
            return V1_Artifact_InternalDataProductType.serialization.fromJson(json);
        default:
            throw new Error(`Unknown V1_DataProductType type: ${json._type}`);
    }
};
export class V1_DataProductInfo {
    path;
    deploymentId;
    description;
    title;
    dataProductType;
    static serialization = new SerializationFactory(createModelSchema(V1_DataProductInfo, {
        path: primitive(),
        deploymentId: primitive(),
        description: optional(primitive()),
        title: optional(primitive()),
        dataProductType: custom((val) => (val ? V1_serializeDataProductType(val) : undefined), (val) => (val ? V1_deserializeDataProductType(val) : undefined)),
    }));
}
export class V1_ResourceBuilder {
}
export class V1_DatabaseDDL extends V1_ResourceBuilder {
    reproducible;
    targetEnvironment;
    script;
    classification;
    resourceType;
    static serialization = new SerializationFactory(createModelSchema(V1_DatabaseDDL, {
        _type: usingConstantValueSchema(V1_ResourceBuilderType.DATABASE_DDL),
        reproducible: primitive(),
        targetEnvironment: primitive(),
        script: primitive(),
        classification: optional(primitive()),
        resourceType: primitive(),
    }));
}
export class V1_FunctionAccessPoint extends V1_ResourceBuilder {
    functionGrammar;
    static serialization = new SerializationFactory(createModelSchema(V1_FunctionAccessPoint, {
        _type: usingConstantValueSchema(V1_ResourceBuilderType.FUNCTION_ACCESS_POINT),
        functionGrammar: primitive(),
    }));
}
export const V1_serializeResourceBuilder = (resourceBuilder) => {
    if (resourceBuilder instanceof V1_DatabaseDDL) {
        return V1_DatabaseDDL.serialization.toJson(resourceBuilder);
    }
    else if (resourceBuilder instanceof V1_FunctionAccessPoint) {
        return V1_FunctionAccessPoint.serialization.toJson(resourceBuilder);
    }
    throw new UnsupportedOperationError();
};
export const V1_deserializeResourceBuilder = (json) => {
    switch (json._type) {
        case V1_ResourceBuilderType.DATABASE_DDL:
            return V1_DatabaseDDL.serialization.fromJson(json);
        case V1_ResourceBuilderType.FUNCTION_ACCESS_POINT:
            return V1_FunctionAccessPoint.serialization.fromJson(json);
        default:
            throw new Error(`Unknown V1_ResourceBuilder type: ${json._type}`);
    }
};
export class V1_AccessPointImplementation {
    id;
    description;
    resourceBuilder;
    relationElement;
    lambdaGenericType;
    static serialization = new SerializationFactory(createModelSchema(V1_AccessPointImplementation, {
        id: primitive(),
        description: optional(primitive()),
        resourceBuilder: custom(V1_serializeResourceBuilder, V1_deserializeResourceBuilder),
        relationElement: optional(custom((val) => serialize(V1_relationElementModelSchema, val), (val) => deserialize(V1_relationElementModelSchema, val))),
        lambdaGenericType: custom((val) => serialize(V1_genericTypeModelSchema, val), (val) => V1_deserializeGenericType(val)),
    }));
}
export class V1_DatasetSpecification {
    name;
    type;
    static serialization = new SerializationFactory(createModelSchema(V1_DatasetSpecification, {
        name: primitive(),
        type: primitive(),
    }));
}
export class V1_RuntimeGenerationInfo {
    path;
    storePath;
    connectionType;
    static serialization = new SerializationFactory(createModelSchema(V1_RuntimeGenerationInfo, {
        path: primitive(),
        storePath: optional(primitive()),
        connectionType: optional(primitive()),
    }));
}
export class V1_DiagramInfo {
    title;
    description;
    diagram;
    static serialization = new SerializationFactory(createModelSchema(V1_DiagramInfo, {
        title: primitive(),
        description: optional(primitive()),
        diagram: primitive(),
    }));
}
export class V1_MappingGenerationInfo {
    path;
    model;
    mappedEntities = [];
    static serialization = new SerializationFactory(createModelSchema(V1_MappingGenerationInfo, {
        path: primitive(),
        model: V1_pureModelContextDataPropSchema,
        mappedEntities: list(usingModelSchema(V1_MappedEntity.serialization.schema)),
    }));
}
export class V1_NativeModelExecutionContextInfo {
    key;
    mapping;
    runtimeGeneration;
    datasets = [];
    static serialization = new SerializationFactory(createModelSchema(V1_NativeModelExecutionContextInfo, {
        key: primitive(),
        mapping: primitive(),
        runtimeGeneration: optionalCustomUsingModelSchema(V1_RuntimeGenerationInfo.serialization.schema),
        datasets: list(usingModelSchema(V1_DatasetSpecification.serialization.schema)),
    }));
}
export class V1_ExecutableInfo {
    id;
    executionContextKey;
    query;
}
export class V1_TemplateExecutableInfo extends V1_ExecutableInfo {
    static serialization = new SerializationFactory(createModelSchema(V1_TemplateExecutableInfo, {
        _type: usingConstantValueSchema(V1_ExecutableInfoType.TEMPLATE),
        id: optional(primitive()),
        executionContextKey: optional(primitive()),
        query: primitive(),
    }));
}
export class V1_FunctionPointerExecutableInfo extends V1_ExecutableInfo {
    function;
    static serialization = new SerializationFactory(createModelSchema(V1_FunctionPointerExecutableInfo, {
        _type: usingConstantValueSchema(V1_ExecutableInfoType.FUNCTION_POINTER),
        id: optional(primitive()),
        executionContextKey: optional(primitive()),
        function: primitive(),
        query: primitive(),
    }));
}
export class V1_ServiceExecutableInfo extends V1_ExecutableInfo {
    pattern;
    mapping;
    runtime;
    datasets = [];
    static serialization = new SerializationFactory(createModelSchema(V1_ServiceExecutableInfo, {
        _type: usingConstantValueSchema(V1_ExecutableInfoType.SERVICE),
        id: optional(primitive()),
        executionContextKey: optional(primitive()),
        datasets: list(usingModelSchema(V1_DatasetSpecification.serialization.schema)),
        mapping: optional(primitive()),
        pattern: primitive(),
        query: primitive(),
        runtime: optional(primitive()),
    }));
}
export class V1_MultiExecutionServiceKeyedExecutableInfo {
    key;
    mapping;
    runtime;
    datasets = [];
    static serialization = new SerializationFactory(createModelSchema(V1_MultiExecutionServiceKeyedExecutableInfo, {
        key: primitive(),
        mapping: optional(primitive()),
        runtime: optional(primitive()),
        datasets: list(usingModelSchema(V1_DatasetSpecification.serialization.schema)),
    }));
}
export class V1_MultiExecutionServiceExecutableInfo extends V1_ExecutableInfo {
    pattern;
    keyedExecutableInfos = [];
    static serialization = new SerializationFactory(createModelSchema(V1_MultiExecutionServiceExecutableInfo, {
        _type: usingConstantValueSchema(V1_ExecutableInfoType.MULTI_EXECUTION_SERVICE),
        id: optional(primitive()),
        executionContextKey: optional(primitive()),
        keyedExecutableInfos: list(usingModelSchema(V1_MultiExecutionServiceKeyedExecutableInfo.serialization.schema)),
        pattern: primitive(),
        query: primitive(),
    }));
}
const V1_deserializeExecutableInfo = (json) => {
    switch (json._type) {
        case V1_ExecutableInfoType.TEMPLATE:
            return V1_TemplateExecutableInfo.serialization.fromJson(json);
        case V1_ExecutableInfoType.FUNCTION_POINTER:
            return V1_FunctionPointerExecutableInfo.serialization.fromJson(json);
        case V1_ExecutableInfoType.SERVICE:
            return V1_ServiceExecutableInfo.serialization.fromJson(json);
        case V1_ExecutableInfoType.MULTI_EXECUTION_SERVICE:
            return V1_MultiExecutionServiceExecutableInfo.serialization.fromJson(json);
        default:
            throw new UnsupportedOperationError(`Can't deserialize executable info of type '${json._type}'`);
    }
};
// ========================
// Executable Result classes
// ========================
export class V1_ExecutableTDSResultColumn {
    name;
    type;
    relationalType;
    doc;
    static serialization = new SerializationFactory(createModelSchema(V1_ExecutableTDSResultColumn, {
        name: primitive(),
        type: optional(primitive()),
        relationalType: optional(primitive()),
        doc: optional(primitive()),
    }));
}
export class V1_ExecutableTDSResultInfo {
    tdsColumns = [];
    static serialization = new SerializationFactory(createModelSchema(V1_ExecutableTDSResultInfo, {
        _type: usingConstantValueSchema(V1_ExecutableResultType.TDS),
        tdsColumns: list(usingModelSchema(V1_ExecutableTDSResultColumn.serialization.schema)),
    }));
}
export class V1_ExecutableResult {
}
export class V1_ExecutableTDSResult extends V1_ExecutableResult {
    tdsResult;
    static serialization = new SerializationFactory(createModelSchema(V1_ExecutableTDSResult, {
        _type: usingConstantValueSchema(V1_ExecutableResultType.TDS),
        tdsResult: usingModelSchema(V1_ExecutableTDSResultInfo.serialization.schema),
    }));
}
export class V1_ExecutableRelationResult extends V1_ExecutableResult {
    genericType;
    static serialization = new SerializationFactory(createModelSchema(V1_ExecutableRelationResult, {
        _type: usingConstantValueSchema(V1_ExecutableResultType.RELATION),
        genericType: custom((val) => serialize(V1_genericTypeModelSchema, val), (val) => V1_deserializeGenericType(val)),
    }));
}
const V1_deserializeExecutableResult = (json) => {
    switch (json._type) {
        case V1_ExecutableResultType.TDS:
            return V1_ExecutableTDSResult.serialization.fromJson(json);
        case V1_ExecutableResultType.RELATION:
            return V1_ExecutableRelationResult.serialization.fromJson(json);
        default:
            throw new UnsupportedOperationError(`Can't deserialize executable result of type '${json._type}'`);
    }
};
export class V1_SampleQuery {
    title;
    description;
    executable;
    info;
    result;
    static serialization = new SerializationFactory(createModelSchema(V1_SampleQuery, {
        title: primitive(),
        description: optional(primitive()),
        executable: optional(primitive()),
        info: custom(() => SKIP, (val) => V1_deserializeExecutableInfo(val)),
        result: custom(() => SKIP, (val) => V1_deserializeExecutableResult(val)),
    }));
}
export class V1_NativeModelAccessInfo {
    diagrams = [];
    model;
    elements = [];
    defaultExecutionContext;
    elementDocs = [];
    mappingGenerations;
    nativeModelExecutionContexts;
    sampleQueries;
    static serialization = new SerializationFactory(createModelSchema(V1_NativeModelAccessInfo, {
        diagrams: list(usingModelSchema(V1_DiagramInfo.serialization.schema)),
        model: V1_pureModelContextDataPropSchema,
        elements: list(primitive()),
        elementDocs: list(custom(() => SKIP, V1_deserializeModelDocumentationEntry)),
        defaultExecutionContext: primitive(),
        nativeModelExecutionContexts: list(usingModelSchema(V1_NativeModelExecutionContextInfo.serialization.schema)),
        sampleQueries: optionalCustomList(() => SKIP, (val) => V1_SampleQuery.serialization.fromJson(val)),
        mappingGenerations: custom(() => SKIP, (val) => deserializeMap(val, (_val) => deserialize(V1_MappingGenerationInfo.serialization.schema, _val))),
    }));
}
export class V1_BasicDocumentationEntry {
    name;
    docs = [];
    static serialization = new SerializationFactory(createModelSchema(V1_BasicDocumentationEntry, {
        docs: list(primitive()),
        name: primitive(),
    }));
}
export class V1_PropertyDocumentationEntry extends V1_BasicDocumentationEntry {
    milestoning;
    type;
    multiplicity;
    static serialization = new SerializationFactory(createModelSchema(V1_PropertyDocumentationEntry, {
        docs: list(primitive()),
        milestoning: optional(primitive()),
        multiplicity: usingModelSchema(V1_multiplicityModelSchema),
        name: primitive(),
        type: optional(primitive()),
    }));
}
export class V1_ModelDocumentationEntry extends V1_BasicDocumentationEntry {
    path;
    static serialization = new SerializationFactory(createModelSchema(V1_ModelDocumentationEntry, {
        docs: list(primitive()),
        name: primitive(),
        path: primitive(),
    }));
}
export class V1_ClassDocumentationEntry extends V1_ModelDocumentationEntry {
    properties = [];
    milestoning;
    static serialization = new SerializationFactory(createModelSchema(V1_ClassDocumentationEntry, {
        docs: list(primitive()),
        milestoning: optional(primitive()),
        name: primitive(),
        path: primitive(),
        properties: list(object(V1_PropertyDocumentationEntry)),
    }));
}
export class V1_EnumerationDocumentationEntry extends V1_ModelDocumentationEntry {
    enumValues = [];
    static serialization = new SerializationFactory(createModelSchema(V1_EnumerationDocumentationEntry, {
        enumValues: list(object(V1_BasicDocumentationEntry)),
        docs: list(primitive()),
        name: primitive(),
        path: primitive(),
    }));
}
export class V1_AssociationDocumentationEntry extends V1_ModelDocumentationEntry {
    properties = [];
    static serialization = new SerializationFactory(createModelSchema(V1_AssociationDocumentationEntry, {
        docs: list(primitive()),
        name: primitive(),
        path: primitive(),
        properties: list(object(V1_PropertyDocumentationEntry)),
    }));
}
var V1_ModelDocumentationEntryType;
(function (V1_ModelDocumentationEntryType) {
    V1_ModelDocumentationEntryType["MODEL"] = "model";
    V1_ModelDocumentationEntryType["CLASS"] = "class";
    V1_ModelDocumentationEntryType["ENUMERATION"] = "enumeration";
    V1_ModelDocumentationEntryType["ASSOCIATION"] = "association";
})(V1_ModelDocumentationEntryType || (V1_ModelDocumentationEntryType = {}));
function V1_deserializeModelDocumentationEntry(json) {
    switch (json._type) {
        case V1_ModelDocumentationEntryType.MODEL:
            return V1_ModelDocumentationEntry.serialization.fromJson(json);
        case V1_ModelDocumentationEntryType.CLASS:
            return V1_ClassDocumentationEntry.serialization.fromJson(json);
        case V1_ModelDocumentationEntryType.ENUMERATION:
            return V1_EnumerationDocumentationEntry.serialization.fromJson(json);
        case V1_ModelDocumentationEntryType.ASSOCIATION:
            return V1_AssociationDocumentationEntry.serialization.fromJson(json);
        default:
            throw new UnsupportedOperationError(`Can't deserialize model documentation entry of type '${json._type}'`);
    }
}
export var V1_AccessPointGroupInfoType;
(function (V1_AccessPointGroupInfoType) {
    V1_AccessPointGroupInfoType["MODEL"] = "modelAccessPointGroup";
})(V1_AccessPointGroupInfoType || (V1_AccessPointGroupInfoType = {}));
export class V1_AccessPointGroupInfo {
    id;
    description;
    accessPointImplementations = [];
    static serialization = new SerializationFactory(createModelSchema(V1_AccessPointGroupInfo, {
        id: primitive(),
        description: optional(primitive()),
        accessPointImplementations: list(usingModelSchema(V1_AccessPointImplementation.serialization.schema)),
    }));
}
export class V1_ModelAccessPointGroupInfo extends V1_AccessPointGroupInfo {
    mappingGeneration;
    diagrams = [];
    model;
    elements = [];
    elementDocs = [];
    static serialization = new SerializationFactory(createModelSchema(V1_ModelAccessPointGroupInfo, {
        _type: usingConstantValueSchema(V1_AccessPointGroupInfoType.MODEL),
        id: primitive(),
        description: optional(primitive()),
        accessPointImplementations: list(usingModelSchema(V1_AccessPointImplementation.serialization.schema)),
        mappingGeneration: usingModelSchema(V1_MappingGenerationInfo.serialization.schema),
        diagrams: list(usingModelSchema(V1_DiagramInfo.serialization.schema)),
        model: V1_pureModelContextDataPropSchema,
        elements: list(primitive()),
        elementDocs: list(custom(() => SKIP, V1_deserializeModelDocumentationEntry)),
    }));
}
function V1_deserializeAccessPointGroupInfo(json) {
    switch (json._type) {
        case V1_AccessPointGroupInfoType.MODEL:
            return V1_ModelAccessPointGroupInfo.serialization.fromJson(json);
        default:
            return V1_AccessPointGroupInfo.serialization.fromJson(json);
    }
}
export class V1_DataProductArtifact {
    dataProduct;
    accessPointGroups = [];
    nativeModelAccess;
    static serialization = new SerializationFactory(createModelSchema(V1_DataProductArtifact, {
        dataProduct: usingModelSchema(V1_DataProductInfo.serialization.schema),
        accessPointGroups: list(custom(() => SKIP, (val) => V1_deserializeAccessPointGroupInfo(val))),
        nativeModelAccess: optionalCustomUsingModelSchema(V1_NativeModelAccessInfo.serialization.schema),
    }));
}
//# sourceMappingURL=V1_DataProductArtifact.js.map