/*******************************************************************************
 * Copyright (c) 2020 B2i Healthcare. All rights reserved.
 *******************************************************************************/
package com.b2international.snowowl.snomed.core;

import java.util.function.Function;

import com.b2international.snowowl.core.api.SnowowlRuntimeException;
import com.b2international.snowowl.snomed.core.domain.SnomedConcept;

/**
 * @since 7.10.0
 */
public enum SnomedDisplayTermType {
	
	FSN(
		"Fully specified name", 
		SnomedConcept.Expand.FULLY_SPECIFIED_NAME + "()",
		concept -> concept.getFsn() != null ? concept.getFsn().getTerm() : concept.getId()
	),
	
	PT(
		"Preferred term", 
		SnomedConcept.Expand.PREFERRED_TERM + "()",
		concept -> concept.getPt() != null ? concept.getPt().getTerm() : concept.getId()
	);
	
	private final String label;
	private final String expand;
	private final Function<SnomedConcept, String> getLabel;
	
	private SnomedDisplayTermType(final String label, final String expand, final Function<SnomedConcept, String> getLabel) {
		this.label = label;
		this.expand = expand;
		this.getLabel = getLabel;
	}
	
	public String getLabel() {
		return label;
	}
	
	public String getExpand() {
		return expand;
	}
	
	public String getLabel(SnomedConcept concept) {
		return getLabel.apply(concept);
	}
	
	@Override
	public String toString() {
		return label;
	}

	public static SnomedDisplayTermType getEnum(final String value) {
		try {
			return SnomedDisplayTermType.valueOf(value);
		} catch(Exception e) {
			throw new SnowowlRuntimeException(String.format("Could not find the value of: %s in Enum: %s", value, SnomedDisplayTermType.class.getName()), e);
		}
	}
	
}

@@ -306,77 +306,8 @@
 n;%0A%0A
-import com.b2international.snowowl.core.api.SnowowlRuntimeException;%0A
 impo
@@ -766,16 +766,70 @@
 getId()%0A
+%09),%0A%09%0A%09ID_ONLY(%0A%09%09%22ID%22, %0A%09%09%22%22,%0A%09%09SnomedConcept::getId%0A
 %09);%0A%09%0A%09p
@@ -1547,152 +1547,22 @@
 %0A%09%09%09
-throw new SnowowlRuntimeException(String.format(%22Could not find the value of: %25s in Enum: %25s%22, value, SnomedDisplayTermType.class.getName()), e)
+return ID_ONLY
 ;%0A%09%09

return ID_ONLY enum when value is not found