/*-
 * ~~~~~~licensing~~~~~~
 * object-runtime-shell
 * ==========
 * Copyright (C) 2020 - 2025 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.platform.objects.runtime.shell;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import ru.entaxy.platform.base.objects.EntaxyObject.OBJECT_RELATION;
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObject;
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeObjectContainer;
import ru.entaxy.platform.objects.runtime.EntaxyRuntimeRelation;

public class RuntimeObjectShellUtils {
	
	public static String getContainerPrintString(EntaxyRuntimeObjectContainer container) {
		return "[" + container.getId() + "]" + container.getName();
	}

	public static String getContainerListPrintString(List<EntaxyRuntimeObjectContainer> containers) {
		return getContainerListPrintString(containers, "");
	}
	
	public static String getContainerListPrintString(List<EntaxyRuntimeObjectContainer> containers, String prefix) {
		return containers.stream()
				.map(cnt -> prefix + getContainerPrintString(cnt))
				.collect(Collectors.joining());
				
	}

	public static String getObjectPrintString(EntaxyRuntimeObject object) {
		return object.getObjectFullId();
	}

	public static String getObjectListPrintString(List<EntaxyRuntimeObject> objects) {
		return getObjectListPrintString(objects, "");
	}
	
	public static String getObjectListPrintString(List<EntaxyRuntimeObject> objects, String prefix) {
		return objects.stream()
				.map(obj -> prefix + getObjectPrintString(obj))
				.collect(Collectors.joining());
				
	}

	public static String getRelationPrintString(EntaxyRuntimeRelation relation) {
		return relation.getType().name() + " [" + relation.getName() + " / " + relation.getGroup() + " : " + relation.getScope().name() + "]";
	}
	
	public static String getRelationDependentPrintString(EntaxyRuntimeRelation relation) {
		return getRelationPrintString(relation) + " - " + getObjectPrintString(relation.getDependent());
	}
	
	public static String getRelationMainPrintString(EntaxyRuntimeRelation relation) {
		return getRelationPrintString(relation) + " - " + getObjectPrintString(relation.getMain());
	}
		
	public static String getRelationListMainPrintString(List<EntaxyRuntimeRelation> relations) {
		return getRelationListMainPrintString(relations, "");
	}
	
	public static String getRelationListMainPrintString(List<EntaxyRuntimeRelation> relations, String prefix) {
		return relations.stream()
				.map(obj -> prefix + getRelationMainPrintString(obj))
				.collect(Collectors.joining());
	}

	public static String getRelationListDependentPrintString(List<EntaxyRuntimeRelation> relations) {
		return getRelationListDependentPrintString(relations, "");
	}
	
	public static String getRelationListDependentPrintString(List<EntaxyRuntimeRelation> relations, String prefix) {
		return relations.stream()
				.map(obj -> prefix + getRelationDependentPrintString(obj))
				.collect(Collectors.joining());
	}
	
	public static List<EntaxyRuntimeRelation> getObjectDependenciesAndUses(EntaxyRuntimeObject object) {
		List<EntaxyRuntimeRelation> result = new ArrayList<>(object.getRelations(OBJECT_RELATION.DEPENDENCY));
		result.addAll(object.getRelations(OBJECT_RELATION.USE));
		return result;
	}

	public static List<EntaxyRuntimeRelation> getObjectIncomingDependenciesAndUses(EntaxyRuntimeObject object) {
		List<EntaxyRuntimeRelation> result = new ArrayList<>(object.getIncomiingRelations(OBJECT_RELATION.DEPENDENCY));
		result.addAll(object.getRelations(OBJECT_RELATION.USE));
		return result;
	}
	
}
