/*
 * Copyright 2011-2015 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * 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.
 */
package com.b2international.snowowl.snomed.core.domain;

import java.text.MessageFormat;

import com.b2international.snowowl.snomed.SnomedConstants.Concepts;

/**
 * Enumerates allowed relationship characteristic types and their corresponding concept identifiers.
 * 
 * @see <a href="http://www.snomed.org/tig?t=tsg2_metadata_enumeration_characteristic">Concept enumerations for
 * characteristicTypeId (Technical Implementation Guide)</a>
 */
public enum CharacteristicType implements ConceptEnum {

	/**
	 * The relationship is used as part of the description logic (DL) definition
	 */
	DEFINING_RELATIONSHIP(Concepts.DEFINING_RELATIONSHIP),

	/**
	 * The relationship is defining, and was created by an author (manually)
	 */
	STATED_RELATIONSHIP(Concepts.STATED_RELATIONSHIP),

	/**
	 * The relationship is defining, and was created by the reasoner (automatically)
	 */
	INFERRED_RELATIONSHIP(Concepts.INFERRED_RELATIONSHIP),

	/**
	 * When creating postcoordinated expressions based on the concept, this relationship can be included as a qualifier
	 */
	QUALIFYING_RELATIONSHIP(Concepts.QUALIFYING_RELATIONSHIP),

	/**
	 * The relationship is not part of the DL definition; it only provides supplementary information
	 */
	ADDITIONAL_RELATIONSHIP(Concepts.ADDITIONAL_RELATIONSHIP);

	private final String conceptId;

	private CharacteristicType(final String conceptId) {
		this.conceptId = conceptId;
	}

	/**
	 * Retrieves the concept identifier for this characteristic type.
	 * 
	 * @return the concept identifier corresponding to the characteristic type constant
	 */
	@Override
	public String getConceptId() {
		return conceptId;
	}

	/**
	 * Performs a reverse lookup by concept identifier and returns the matching characteristic type.
	 * 
	 * @param conceptId the concept identifier to look for
	 * 
	 * @return the resolved {@link CharacteristicType}
	 * @throws IllegalArgumentException if no characteristic type matches the specified concept identifier
	 */
	public static CharacteristicType getByConceptId(final String conceptId) {
		for (final CharacteristicType candidate : values()) {
			if (candidate.getConceptId().equals(conceptId)) {
				return candidate;
			}
		}

		throw new IllegalArgumentException(MessageFormat.format("No characteristic type value found for identifier ''{0}''.", conceptId));
	}
	
}

@@ -2948,13 +2948,152 @@
 Id));%0A%09%7D
+%0A%0A%09public boolean isDefining() %7B%0A%09%09return this == DEFINING_RELATIONSHIP %7C%7C this == INFERRED_RELATIONSHIP %7C%7C this == STATED_RELATIONSHIP;%0A%09%7D
 %0A%09%0A%7D%0A

add isDefining() to CharacteristicType