/**
 * 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 { UnsupportedOperationError } from '@finos/legend-shared';
import { DeploymentOwner, UserList, } from '../../../../../../../graph/metamodel/pure/packageableElements/function/Ownership.js';
import { V1_SnowflakeAppDeploymentConfiguration } from '../../../engine/functionActivator/V1_SnowflakeAppDeploymentConfiguration.js';
import { V1_SnowflakeM2MUdfDeploymentConfiguration } from '../../../engine/functionActivator/V1_SnowflakeM2MUdfDeploymentConfiguration.js';
import { V1_DeploymentOwner, V1_UserList, } from '../../../model/packageableElements/function/V1_Ownership.js';
import { V1_transformConnectionPointer } from './V1_ConnectionTransformer.js';
import { V1_HostedServiceDeploymentConfiguration } from '../../../engine/functionActivator/V1_HostedServiceDeploymentConfiguration.js';
import { V1_MemSQLDeploymentConfiguration } from '../../../engine/functionActivator/V1_MemSQLDeploymentConfiguration.js';
import { V1_PostDeploymentAction } from '../../../engine/functionActivator/V1_PostDeploymentAction.js';
export const V1_transformSnowflakeAppDeploymentConfiguration = (element) => {
    const protocol = new V1_SnowflakeAppDeploymentConfiguration();
    if (element.activationConnection) {
        protocol.activationConnection = V1_transformConnectionPointer(element.activationConnection);
    }
    return protocol;
};
export const V1_transformSnowflakeM2MUdfDeploymentConfiguration = (element) => {
    const protocol = new V1_SnowflakeM2MUdfDeploymentConfiguration();
    if (element.activationConnection) {
        protocol.activationConnection = V1_transformConnectionPointer(element.activationConnection);
    }
    return protocol;
};
export const V1_transformMemSQLDeploymentConfiguration = (element) => {
    const protocol = new V1_MemSQLDeploymentConfiguration();
    if (element.activationConnection) {
        protocol.activationConnection = V1_transformConnectionPointer(element.activationConnection);
    }
    return protocol;
};
export const V1_transformDeployment = (metamodel) => {
    const ownership = new V1_DeploymentOwner();
    ownership.id = metamodel.id;
    return ownership;
};
export const V1_transformUserList = (element) => {
    const ownership = new V1_UserList();
    ownership.users = element.users;
    return ownership;
};
export const V1_transformOwnership = (metamodel) => {
    if (metamodel instanceof DeploymentOwner) {
        return V1_transformDeployment(metamodel);
    }
    else if (metamodel instanceof UserList) {
        return V1_transformUserList(metamodel);
    }
    throw new UnsupportedOperationError("Can't transform function activator ownership", metamodel);
};
export const V1_transformActions = (metamodel, context) => {
    const extraFunctionActivatorTransformers = context.plugins.flatMap((plugin) => plugin.V1_getExtraPostDeploymentPropertiesTransformers?.() ?? []);
    for (const transformer of extraFunctionActivatorTransformers) {
        const protocol = [];
        for (const action of metamodel) {
            const actionProtocol = new V1_PostDeploymentAction();
            actionProtocol.automated = action.automated;
            if (action.properties) {
                actionProtocol.properties = transformer(action.properties, context);
            }
            protocol.push(actionProtocol);
        }
        return protocol;
    }
    return [];
};
export const V1_transformHostedServiceDeploymentConfiguration = (element) => {
    const protocol = new V1_HostedServiceDeploymentConfiguration();
    protocol.host = element.host;
    protocol.path = element.path;
    protocol.port = element.port;
    return protocol;
};
//# sourceMappingURL=V1_FunctionActivatorTransformer.js.map