/**
 * 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 { createModelSchema, custom, list, optional, primitive, raw, SKIP, } from 'serializr';
import { SerializationFactory, usingModelSchema, } from '@finos/legend-shared';
import { ExecutionActivityType } from '../../../../../../graph-manager/action/execution/ExecutionResult.js';
export const V1_EXECUTION_RESULT = 'executionResult';
export const V1_ZIPKIN_TRACE_HEADER = 'x-b3-traceid';
export const V1_DELEGATED_EXPORT_HEADER = 'x-legend-delegated-export';
export class V1_ResultBuilder {
    static builderSerialization = new SerializationFactory(createModelSchema(V1_ResultBuilder, {
        _type: primitive(),
    }));
}
export class V1_ExecutionActivities {
}
export class V1_RelationalExecutionActivities extends V1_ExecutionActivities {
    sql;
    comment;
    static serialization = new SerializationFactory(createModelSchema(V1_RelationalExecutionActivities, {
        sql: primitive(),
        comment: optional(primitive()),
    }));
}
export class V1_AggregationAwareActivities extends V1_ExecutionActivities {
    rewrittenQuery;
    static serialization = new SerializationFactory(createModelSchema(V1_AggregationAwareActivities, {
        rewrittenQuery: primitive(),
    }));
}
export class V1_ExecutionResult {
    builder;
    activities;
}
export class V1_UnknownExecutionActivity extends V1_ExecutionActivities {
    content;
    constructor(content) {
        super();
        this.content = content;
    }
}
export class V1_JsonExecutionResult extends V1_ExecutionResult {
    values;
    static serialization = new SerializationFactory(createModelSchema(V1_JsonExecutionResult, {
        _type: primitive(),
        builder: usingModelSchema(V1_ResultBuilder.builderSerialization.schema),
        values: raw(),
    }));
}
/**
 * TODO?: maybe we converge to use V1_TDSColumn
 *
 * Since here, we're building out the result builder config, we don't need
 * to fully resolve all the references, hence we have this simplified version of V1_TDSColumn
 */
export class V1_INTERNAL__TDSColumn {
    name;
    doc;
    type;
    relationalType;
    static serialization = new SerializationFactory(createModelSchema(V1_INTERNAL__TDSColumn, {
        name: primitive(),
        doc: optional(primitive()),
        type: optional(primitive()),
        relationalType: optional(primitive()),
    }));
}
export class V1_TDSBuilder extends V1_ResultBuilder {
    columns = [];
    static serialization = new SerializationFactory(createModelSchema(V1_TDSBuilder, {
        _type: primitive(),
        columns: list(usingModelSchema(V1_INTERNAL__TDSColumn.serialization.schema)),
    }));
}
function V1_serializeExecutionActivities(value) {
    switch (value._type) {
        case ExecutionActivityType.RELATIONAL:
            return V1_RelationalExecutionActivities.serialization.fromJson(value);
        case ExecutionActivityType.RELATIONAL_EXECUTION_ACTIVITY:
            return V1_RelationalExecutionActivities.serialization.fromJson(value);
        case ExecutionActivityType.AGGREGATION_AWARE_ACTIVITY:
            return V1_AggregationAwareActivities.serialization.fromJson(value);
        default:
            return new V1_UnknownExecutionActivity(value);
    }
}
export class V1_TDSExecutionResult extends V1_ExecutionResult {
    result;
    static serialization = new SerializationFactory(createModelSchema(V1_TDSExecutionResult, {
        builder: usingModelSchema(V1_TDSBuilder.serialization.schema),
        activities: list(custom(() => SKIP, V1_serializeExecutionActivities)),
        result: raw(),
    }));
}
export class V1_ClassExecutionResult extends V1_ExecutionResult {
    objects;
    static serialization = new SerializationFactory(createModelSchema(V1_ClassExecutionResult, {
        builder: usingModelSchema(V1_ResultBuilder.builderSerialization.schema),
        activities: list(custom(() => SKIP, V1_serializeExecutionActivities)),
        objects: raw(),
    }));
}
export class V1_RawExecutionResult extends V1_ExecutionResult {
    value;
    constructor(value) {
        super();
        this.value = value;
    }
}
//# sourceMappingURL=V1_ExecutionResult.js.map