/*-
 * ~~~~~~licensing~~~~~~
 * connection
 * ==========
 * Copyright (C) 2020 - 2023 EmDev LLC
 * ==========
 * You may not use this file except in accordance with the License Terms of the Copyright
 * Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
 * rights to the Software and any copies are the property of the Copyright Holder. Unless
 * it is explicitly allowed the Copyright Holder, the User is prohibited from using the
 * Software for commercial purposes to provide services to third parties.
 * 
 * The Copyright Holder hereby declares that the Software is provided on an "AS IS".
 * Under no circumstances does the Copyright Holder guarantee or promise that the
 * Software provided by him will be suitable or not suitable for the specific purposes
 * of the User, that the Software will meet all commercial and personal subjective
 * expectations of the User, that the Software will work properly, without technical
 * errors, quickly and uninterruptedly.
 * 
 * Under no circumstances shall the Copyright Holder or its Affiliates is not liable
 * to the User for any direct or indirect losses of the User, his expenses or actual
 * damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
 * or damage to data, property, etc.
 * ~~~~~~/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);
    }

*/
}
