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

import org.osgi.resource.Capability;
import java.util.Map;

public interface CapabilityDescriptor extends Capability {

	public static final String HEADER_PROVIDE_CAPABILITY = "Provide-Capability";
	public static final String HEADER_REQUIRE_CAPABILITY = "Require-Capability";
	
	public static interface ATTRIBUTE_TYPES {
		
		public static final String STRING = "String";
		public static final String VERSION = "Version";
		public static final String LONG = "Long";
		public static final String DOUBLE = "Double";
		public static final String LIST = "List";
		
		public static String TYPED_LIST(String itemType) {
			return LIST + "<" + itemType + ">";
		}

		public static boolean isList(String itemType) {
			return (itemType!=null) && (itemType.startsWith(LIST));
		}

		public static String itemType(String listType) {
			if (!isList(listType))
				return null;
			
			return listType.substring(listType.indexOf("<"), listType.indexOf(">"));
		}
		
	}
	
	public CapabilityDescriptor namespace(String namespace);
	public CapabilityDescriptor attributes(Map<String, Object> attributes);
	public CapabilityDescriptor attribute(String name, Object value);
	public CapabilityDescriptor attribute(String name, Object value, String type);
	
}
