/*
 * Copyright 2011-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.snomed.datastore.request;

import static com.google.common.collect.Maps.newHashMap;

import java.util.Map;

import com.b2international.snowowl.snomed.common.SnomedConstants.Concepts;
import com.b2international.snowowl.snomed.core.domain.Acceptability;

/**
 * <i>Builder</i> class to build requests responsible for creating SNOMED CT descriptions.
 * This class should be instantiated from the corresponding static method on the central {@link SnomedRequests} class.
 * 
 * @since 4.5
 */
public final class SnomedDescriptionCreateRequestBuilder extends SnomedComponentCreateRequestBuilder<SnomedDescriptionCreateRequestBuilder> {

	private String caseSignificanceId = Concepts.ONLY_INITIAL_CHARACTER_CASE_INSENSITIVE;
	private String term;
	private String conceptId;
	private String typeId = Concepts.SYNONYM;
	private String languageCode = "en";
	private Map<String, Acceptability> acceptabilityMap = newHashMap();
	private String inactivationIndicatorId = "";
	
	SnomedDescriptionCreateRequestBuilder() { 
		super();
	}
	
	public SnomedDescriptionCreateRequestBuilder setCaseSignificanceId(String caseSignificanceId) {
		this.caseSignificanceId = caseSignificanceId;
		return getSelf();
	}
	
	public SnomedDescriptionCreateRequestBuilder setTerm(String term) {
		this.term = term;
		return getSelf();
	}

	public SnomedDescriptionCreateRequestBuilder setConceptId(String conceptId) {
		this.conceptId = conceptId;
		return getSelf();
	}
	
	public SnomedDescriptionCreateRequestBuilder setTypeId(String typeId) {
		this.typeId = typeId;
		return getSelf();
	}
	
	public SnomedDescriptionCreateRequestBuilder setLanguageCode(String languageCode) {
		this.languageCode = languageCode;
		return getSelf();
	}
	
	public SnomedDescriptionCreateRequestBuilder acceptableIn(String languageReferenceSetId) {
		this.acceptabilityMap.put(languageReferenceSetId, Acceptability.ACCEPTABLE);
		return getSelf();
	}
	
	public SnomedDescriptionCreateRequestBuilder preferredIn(String languageReferenceSetId) {
		this.acceptabilityMap.put(languageReferenceSetId, Acceptability.PREFERRED);
		return getSelf();
	}
	
	public SnomedDescriptionCreateRequestBuilder setAcceptability(Map<String, Acceptability> acceptabilityMap) {
		this.acceptabilityMap.putAll(acceptabilityMap);
		return getSelf();
	}
	
	public SnomedDescriptionCreateRequestBuilder setInactivationIndicator(String inactivationIndicatorId) {
		this.inactivationIndicatorId = inactivationIndicatorId;
		return getSelf();
	}
	
	@Override
	protected BaseSnomedComponentCreateRequest createRequest() {
		return new SnomedDescriptionCreateRequest();
	}
	
	@Override
	protected void init(BaseSnomedComponentCreateRequest request) {
		final SnomedDescriptionCreateRequest req = (SnomedDescriptionCreateRequest) request;
		req.setCaseSignificanceId(caseSignificanceId);
		req.setTerm(term);
		req.setConceptId(conceptId);
		req.setTypeId(typeId);
		req.setLanguageCode(languageCode);
		req.setAcceptability(acceptabilityMap);
		req.setInactivationIndicatorId(inactivationIndicatorId);
	}


}

@@ -2863,24 +2863,59 @@
 ilityMap) %7B%0A
+%09%09if (acceptabilityMap != null) %7B%0A%09
 %09%09this.accep
@@ -2948,24 +2948,28 @@
 bilityMap);%0A
+%09%09%7D%0A
 %09%09return get

fix possible NPE when not supplying any acceptability values