/**
 * 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 { SerializationFactory, UnsupportedOperationError, optionalCustom, usingConstantValueSchema, usingModelSchema, } from '@finos/legend-shared';
import { createModelSchema, deserialize, list, optional, primitive, raw, serialize, } from 'serializr';
import { V1_stereotypePtrModelSchema, V1_taggedValueModelSchema, } from '../../transformation/pureProtocol/serializationHelpers/V1_CoreSerializationHelper.js';
export class V1_QueryParameterValue {
    name;
    content;
    static serialization = new SerializationFactory(createModelSchema(V1_QueryParameterValue, {
        name: primitive(),
        content: primitive(),
    }), {
        deserializeNullAsUndefined: true,
    });
}
export class V1_QueryExecutionContext {
}
export var V1_QueryExecutionContextType;
(function (V1_QueryExecutionContextType) {
    V1_QueryExecutionContextType["QUERY_EXPLICIT_EXECUTION_CONTEXT"] = "explicitExecutionContext";
    V1_QueryExecutionContextType["QUERY_DATASAPCE_EXECUTION_CONTEXT"] = "dataSpaceExecutionContext";
    V1_QueryExecutionContextType["QUERY_DATAPRODUCT_NATIVE_EXECUTION_CONTEXT"] = "dataProductNativeExecutionContext";
    V1_QueryExecutionContextType["QUERY_DATAPRODUCT_MODEL_ACCESS_EXECUTION_CONTEXT"] = "dataProductModelAccessExecutionContext";
    V1_QueryExecutionContextType["QUERY_DATAPRODUCT_LAKEHOUSE_EXECUTION_CONTEXT"] = "dataProductLakehouseAccessExecutionContext";
})(V1_QueryExecutionContextType || (V1_QueryExecutionContextType = {}));
export class V1_QueryExplicitExecutionContext extends V1_QueryExecutionContext {
    mapping;
    runtime;
    static serialization = new SerializationFactory(createModelSchema(V1_QueryExplicitExecutionContext, {
        _type: usingConstantValueSchema(V1_QueryExecutionContextType.QUERY_EXPLICIT_EXECUTION_CONTEXT),
        mapping: primitive(),
        runtime: primitive(),
    }), {
        deserializeNullAsUndefined: true,
    });
}
export class V1_QueryDataSpaceExecutionContext extends V1_QueryExecutionContext {
    dataSpacePath;
    executionKey;
    static serialization = new SerializationFactory(createModelSchema(V1_QueryDataSpaceExecutionContext, {
        _type: usingConstantValueSchema(V1_QueryExecutionContextType.QUERY_DATASAPCE_EXECUTION_CONTEXT),
        dataSpacePath: primitive(),
        executionKey: optional(primitive()),
    }), {
        deserializeNullAsUndefined: true,
    });
}
export class V1_QueryDataProductExecutionContext extends V1_QueryExecutionContext {
    dataProductPath;
}
export class V1_DataProductNativeExecutionContext extends V1_QueryDataProductExecutionContext {
    executionKey;
    static serialization = new SerializationFactory(createModelSchema(V1_DataProductNativeExecutionContext, {
        _type: usingConstantValueSchema(V1_QueryExecutionContextType.QUERY_DATAPRODUCT_NATIVE_EXECUTION_CONTEXT),
        dataProductPath: primitive(),
        executionKey: primitive(),
    }), {
        deserializeNullAsUndefined: true,
    });
}
export class V1_DataProductModelAccessExecutionContext extends V1_QueryDataProductExecutionContext {
    accessPointGroupId;
    static serialization = new SerializationFactory(createModelSchema(V1_DataProductModelAccessExecutionContext, {
        _type: usingConstantValueSchema(V1_QueryExecutionContextType.QUERY_DATAPRODUCT_MODEL_ACCESS_EXECUTION_CONTEXT),
        dataProductPath: primitive(),
        accessPointGroupId: primitive(),
    }), {
        deserializeNullAsUndefined: true,
    });
}
export class V1_DataProductLakehouseExecutionContext extends V1_QueryDataProductExecutionContext {
    accessPointId;
    accessGroupId;
    static serialization = new SerializationFactory(createModelSchema(V1_DataProductLakehouseExecutionContext, {
        _type: usingConstantValueSchema(V1_QueryExecutionContextType.QUERY_DATAPRODUCT_LAKEHOUSE_EXECUTION_CONTEXT),
        dataProductPath: primitive(),
        accessPointId: primitive(),
        accessGroupId: primitive(),
    }), {
        deserializeNullAsUndefined: true,
    });
}
export const V1_deserializeQueryExecutionContext = (json) => {
    switch (json._type) {
        case V1_QueryExecutionContextType.QUERY_EXPLICIT_EXECUTION_CONTEXT:
            return deserialize(V1_QueryExplicitExecutionContext.serialization.schema, json);
        case V1_QueryExecutionContextType.QUERY_DATASAPCE_EXECUTION_CONTEXT:
            return deserialize(V1_QueryDataSpaceExecutionContext.serialization.schema, json);
        case V1_QueryExecutionContextType.QUERY_DATAPRODUCT_NATIVE_EXECUTION_CONTEXT:
            return deserialize(V1_DataProductNativeExecutionContext.serialization.schema, json);
        case V1_QueryExecutionContextType.QUERY_DATAPRODUCT_MODEL_ACCESS_EXECUTION_CONTEXT:
            return deserialize(V1_DataProductModelAccessExecutionContext.serialization.schema, json);
        case V1_QueryExecutionContextType.QUERY_DATAPRODUCT_LAKEHOUSE_EXECUTION_CONTEXT:
            return deserialize(V1_DataProductLakehouseExecutionContext.serialization.schema, json);
        default: {
            throw new UnsupportedOperationError(`Can't deserialize authentication strategy of type '${json._type}': no compatible deserializer available from plugins`);
        }
    }
};
export const V1_serializeQueryExecutionContext = (protocol) => {
    if (protocol instanceof V1_QueryExplicitExecutionContext) {
        return serialize(V1_QueryExplicitExecutionContext.serialization.schema, protocol);
    }
    else if (protocol instanceof V1_QueryDataSpaceExecutionContext) {
        return serialize(V1_QueryDataSpaceExecutionContext.serialization.schema, protocol);
    }
    else if (protocol instanceof V1_DataProductNativeExecutionContext) {
        return serialize(V1_DataProductNativeExecutionContext.serialization.schema, protocol);
    }
    else if (protocol instanceof V1_DataProductModelAccessExecutionContext) {
        return serialize(V1_DataProductModelAccessExecutionContext.serialization.schema, protocol);
    }
    else if (protocol instanceof V1_DataProductLakehouseExecutionContext) {
        return serialize(V1_DataProductLakehouseExecutionContext.serialization.schema, protocol);
    }
    throw new UnsupportedOperationError(`Can't serialize authentication strategy: no compatible serializer available from plugins`, protocol);
};
export class V1_Query {
    name;
    id;
    groupId;
    artifactId;
    versionId;
    description;
    originalVersionId;
    content;
    owner;
    taggedValues;
    stereotypes;
    defaultParameterValues;
    lastUpdatedAt;
    createdAt;
    lastOpenAt;
    gridConfig;
    executionContext;
    /**
     * mapping, runtime have been deprecated in favor of `V1_QueryExecutionContext`
     * @deprecated
     */
    mapping;
    /**
     * @deprecated
     */
    runtime;
    static serialization = new SerializationFactory(createModelSchema(V1_Query, {
        artifactId: primitive(),
        content: primitive(),
        id: primitive(),
        defaultParameterValues: optional(list(usingModelSchema(V1_QueryParameterValue.serialization.schema))),
        groupId: primitive(),
        lastUpdatedAt: optional(primitive()),
        createdAt: optional(primitive()),
        lastOpenAt: optional(primitive()),
        mapping: optional(primitive()),
        name: primitive(),
        description: optional(primitive()),
        owner: optional(primitive()),
        runtime: optional(primitive()),
        stereotypes: optional(list(usingModelSchema(V1_stereotypePtrModelSchema))),
        executionContext: optionalCustom((val) => V1_serializeQueryExecutionContext(val), (val) => V1_deserializeQueryExecutionContext(val)),
        taggedValues: optional(list(usingModelSchema(V1_taggedValueModelSchema))),
        versionId: primitive(),
        originalVersionId: optional(primitive()),
        gridConfig: optional(raw()),
    }), {
        deserializeNullAsUndefined: true,
    });
}
export class V1_LightQuery {
    name;
    id;
    groupId;
    owner;
    artifactId;
    versionId;
    originalVersionId;
    description;
    lastUpdatedAt;
    createdAt;
    lastOpenAt;
    static serialization = new SerializationFactory(createModelSchema(V1_Query, {
        artifactId: primitive(),
        id: primitive(),
        groupId: primitive(),
        lastUpdatedAt: optional(primitive()),
        createdAt: optional(primitive()),
        lastOpenAt: optional(primitive()),
        name: primitive(),
        owner: optional(primitive()),
        description: optional(primitive()),
        versionId: primitive(),
        originalVersionId: optional(primitive()),
    }), {
        deserializeNullAsUndefined: true,
    });
}
//# sourceMappingURL=V1_Query.js.map