/*-
 * ~~~~~~licensing~~~~~~
 * artifact-management
 * ==========
 * 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.core.artifact.impl;

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

import org.osgi.resource.Resource;

import ru.entaxy.platform.base.support.osgi.bundle.CapabilityDescriptor;

@Deprecated(forRemoval = true, since = "1.8.2")
public class CapabilityDescriptorImpl implements CapabilityDescriptor {

	protected String namespace;
	
	protected Map<String, String> directives = new HashMap<>();
	protected Map<String, AttributeDescriptor> attributes = new HashMap<>(); 
	
	private static class AttributeDescriptor {
		String type;
		String value;
		Object typedValue;
		
		public AttributeDescriptor(String value) {
			this(value, "String");
		}
		
		public AttributeDescriptor(String value, String type) {
			this.type = type;
			this.value = value;
			
			// TODO convert types if needed
			this.typedValue = value;
		}
	}		
			
	public CapabilityDescriptorImpl() {
		// TODO Auto-generated constructor stub
	}

	public CapabilityDescriptorImpl(String namespace) {
		this();
		namespace(namespace);
	}
	
	public String getAttributesAsString() {
		String result = "";
		for (Map.Entry<String, AttributeDescriptor> entry: this.attributes.entrySet()) {
			if (!result.isEmpty())
				result += ";";
			result += entry.getKey();
			if (!"String".equals(entry.getValue().type))
				result += ":" + entry.getValue().type;
			result += "=" + entry.getValue().value;
		}
		return result;
	}
	
	@Override
	public String getNamespace() {
		return this.namespace;
	}

	@Override
	public Map<String, String> getDirectives() {
		return this.directives;
	}

	@Override
	public Map<String, Object> getAttributes() {
		Map<String, Object> result = new HashMap<>();
		for (Map.Entry<String, AttributeDescriptor> entry: this.attributes.entrySet())
			result.put(entry.getKey(), entry.getValue().typedValue);
		return result;
	}

	@Override
	public Resource getResource() {
		// not implemented
		return null;
	}

	@Override
	public CapabilityDescriptor namespace(String namespace) {
		this.namespace = namespace;
		return this;
	}



	@Override
	public CapabilityDescriptor attributes(Map<String, Object> attributes) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CapabilityDescriptor attribute(String name, Object value) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CapabilityDescriptor attribute(String name, Object value, String type) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> getRawAttributes() {
		// TODO Auto-generated method stub
		return null;
	}

}
