/*
 * Copyright 2020 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.core.domain;

import java.util.SortedSet;

import com.b2international.snowowl.core.uri.ComponentURI;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * @since 7.5
 */
public final class Concept extends BaseComponent {

	private static final long serialVersionUID = 1L;

	private final String codeSystem;
	private final short terminologyComponentId;
	
	private String term;
	private String iconId;
	private SortedSet<String> alternativeTerms;
	
	public Concept(String codeSystem, short terminologyComponentId) {
		this.codeSystem = codeSystem;
		this.terminologyComponentId = terminologyComponentId;
	}
	
	public String getCodeSystem() {
		return codeSystem;
	}
	
	public String getTerm() {
		return term;
	}
	
	public String getIconId() {
		return iconId;
	}
	
	public void setTerm(String term) {
		this.term = term;
	}
	
	public void setIconId(String iconId) {
		this.iconId = iconId;
	}
	
	public void setAlternativeTerms(SortedSet<String> alternativeTerms) {
		this.alternativeTerms = alternativeTerms;
	}
	
	public SortedSet<String> getAlternativeTerms() {
		return alternativeTerms;
	}
	
	@Override
	public short getTerminologyComponentId() {
		return terminologyComponentId;
	}

	@JsonIgnore
	public ComponentURI getCode() {
		return ComponentURI.of(codeSystem, terminologyComponentId, getId());
	}
	
}

@@ -804,16 +804,55 @@
 nIgnore;
+%0Aimport com.google.common.base.Strings;
 %0A%0A/**%0A *
@@ -2007,10 +2007,722 @@
 );%0A%09%7D%0A%09%0A
+%09@Override%0A%09public String toString() %7B%0A%09%09return toConceptString(getId(), getTerm());%0A%09%7D%0A%09%0A%09public static final String toConceptString(String id, String term) %7B%0A%09%09return String.format(%22%25s %7C%25s%7C%22, id, term);%0A%09%7D%0A%09%0A%09public static final String%5B%5D fromConceptString(String conceptString) %7B%0A%09%09if (Strings.isNullOrEmpty(conceptString)) return new String%5B%5D %7B%22%22, %22%22%7D;%0A%09%09final int firstPipeIdx = conceptString.indexOf(%22%7C%22);%0A%09%09final int lastPipeIdx = conceptString.lastIndexOf(%22%7C%22);%0A%09%09return new String%5B%5D %7B%0A%09%09%09conceptString.substring(0, firstPipeIdx == -1 ? conceptString.length() : firstPipeIdx).trim(),%0A%09%09%09conceptString.substring(firstPipeIdx + 1, lastPipeIdx == -1 ? conceptString.length() : lastPipeIdx).trim(),%0A%09%09%7D;%0A%09%7D%0A%09%0A
 %7D%0A

add support for ID|TERM| like concept String format ser/deser