/*-
 * ~~~~~~licensing~~~~~~
 * connection
 * ==========
 * Copyright (C) 2020 - 2021 EmDev LLC
 * ==========
 * 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.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.esb.platform.runtime.base.connecting.connection.util;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ru.entaxy.esb.platform.runtime.base.connecting.adapter.core.api.Adapter;
import ru.entaxy.esb.platform.runtime.base.connecting.adapter.core.util.AdapterUtil;
import ru.entaxy.esb.platform.runtime.base.connecting.adapter.core.util.ConnectionUsageType;
import ru.entaxy.esb.platform.runtime.base.connecting.connection.Connection;
import ru.entaxy.esb.platform.runtime.base.connecting.generator.Generated;

public class ConnectionUtil {
    private static final Logger log = LoggerFactory.getLogger(ConnectionUtil.class);

    // TODO: 09.07.2021 Artifact wrapper needed instead of Blueprint (not only blueprint can be return from generator)

    public static Generated get(Connection connection, String usageType) throws Exception {
        Adapter adapter = AdapterUtil.getAdapter(connection.getAdapterName());
        Map<String, Object> map = new HashMap<>();
        map.put("connectionName", connection.getName());
        map.put("connection", connection);
        return adapter.generate(usageType, map);
    }
    public static Generated getInit(Connection connection) throws Exception {
        return get(connection, ConnectionUsageType.INIT);
    }
    
    public static Generated getRef(Connection connection) throws Exception {
        return get(connection, ConnectionUsageType.REF);
    }
    
    public static Generated getFrom(Connection connection) throws Exception {
        return get(connection, ConnectionUsageType.FROM);
    }
    
    public static Generated getTo(Connection connection) throws Exception {
        return get(connection, ConnectionUsageType.TO);
    }
    
/*    
    @Deprecated
    public static Blueprint getBlueprint(Connection connection, String usageType) throws Exception {
        Adapter adapter = AdapterUtil.getAdapter(connection.getAdapterName());
        Map<String, Object> map = new HashMap<>();
        map.put("connectionName", connection.getName());
        map.put("connection", connection);
        return adapter.generateBlueprint(usageType, map);
    }
    @Deprecated
    public static Blueprint getBlueprintInit(Connection connection) throws Exception {
        return getBlueprint(connection, ConnectionUsageType.INIT);
    }
    
    @Deprecated
    public static Blueprint getBlueprintRef(Connection connection) throws Exception {
        return getBlueprint(connection, ConnectionUsageType.REF);
    }
    
    @Deprecated
    public static Blueprint getBlueprintFrom(Connection connection) throws Exception {
        return getBlueprint(connection, ConnectionUsageType.FROM);
    }
    
    @Deprecated
    public static Blueprint getBlueprintTo(Connection connection) throws Exception {
        return getBlueprint(connection, ConnectionUsageType.TO);
    }

*/
}
