/*
 * Copyright 2018 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.commit;

import java.io.Serializable;

import com.b2international.commons.ChangeKind;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

/**
 * @since 6.6
 */
@JsonDeserialize(builder=CommitInfoDetail.Builder.class)
public final class CommitInfoDetail implements Serializable {
	
	public static Builder builder() {
		return new Builder();
	}
	
	@JsonPOJOBuilder(withPrefix="")
	public static class Builder {
		
		private ChangeKind changeKind;
		private String objectType;
		private String object;
		private String property;
		private String fromValue;
		private String valueType;
		private String value;
		
		Builder() {
		}
		
		public Builder changeKind(ChangeKind changeKind) {
			this.changeKind = changeKind;
			return this;
		}

		public Builder objectType(String objectType) {
			this.objectType = objectType;
			return this;
		}
		
		public Builder object(String object) {
			this.object = object;
			return this;
		}
		
		public Builder property(String property) {
			this.property = property;
			return this;
		}
		
		public Builder fromValue(String fromValue) {
			this.fromValue = fromValue;
			return this;
		}
		
		public Builder valueType(String valueType) {
			this.valueType = valueType;
			return this;
		}
		
		public Builder value(String value) {
			this.value = value;
			return this;
		}
		
		public CommitInfoDetail build() {
			return new CommitInfoDetail(changeKind, objectType, object, property, fromValue, valueType, value);
		}
		
	}
	
	private final ChangeKind changeKind;
	private final String objectType;
	private final String object;
	private final String property;
	private final String fromValue;
	private final String valueType;
	private final String value;
	
	private CommitInfoDetail(ChangeKind changeKind, 
			String objectType, 
			String object, 
			String property, 
			String fromValue,
			String valueType, 
			String value) {
		
		this.changeKind = changeKind;
		this.objectType = objectType;
		this.object = object;
		this.property = property;
		this.fromValue = fromValue;
		this.valueType = valueType;
		this.value = value;
	}
	
	public ChangeKind getChangeKind() {
		return changeKind;
	}
	
	public String getObjectType() {
		return objectType;
	}
	
	public String getObject() {
		return object;
	}
	
	public String getProperty() {
		return property;
	}
	
	public String getFromValue() {
		return fromValue;
	}
	
	public String getValueType() {
		return valueType;
	}
	
	public String getValue() {
		return value;
	}
}

@@ -13,16 +13,21 @@
 ght 2018
+-2020
  B2i Hea
@@ -704,54 +704,247 @@
 le;%0A
-%0Aimport com.b2international.commons.ChangeKind
+import java.util.Collections;%0Aimport java.util.List;%0A%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport com.b2international.commons.ChangeKind;%0Aimport com.fasterxml.jackson.databind.MappingIterator;%0Aimport com.fasterxml.jackson.databind.ObjectMapper
 ;%0Aim
@@ -1072,16 +1072,64 @@
 Builder;
+%0Aimport com.google.common.collect.ImmutableList;
 %0A%0A/**%0A *
@@ -1265,16 +1265,86 @@
 ble %7B%0A%09%0A
+%09private static final long serialVersionUID = -7281465496715002676L;%0A%0A
 %09public 
@@ -3521,10 +3521,748 @@
 lue;%0A%09%7D%0A
+%09%0A%09public %3CT%3E List%3CT%3E parseFromValue(ObjectMapper mapper, Class%3CT%3E type) %7B%0A%09%09return parseJsonValues(mapper, type, fromValue);%0A%09%7D%0A%09%0A%09public %3CT%3E List%3CT%3E parseValue(ObjectMapper mapper, Class%3CT%3E type) %7B%0A%09%09return parseJsonValues(mapper, type, value);%0A%09%7D%0A%0A%09private %3CT%3E List%3CT%3E parseJsonValues(ObjectMapper mapper, Class%3CT%3E type, String json) %7B%0A%09%09try %7B%0A%09%09%09final ImmutableList.Builder%3CT%3E values = ImmutableList.builder();%0A%09%09%09MappingIterator%3CT%3E it = mapper.readerFor(type).readValues(json);%0A%09%09%09while (it.hasNext()) %7B%0A%09%09%09%09values.add(it.next());%0A%09%09%09%7D%0A%09%09%09return values.build();%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09LoggerFactory.getLogger(getClass()).error(%22Couldn't parse fromValue to type %22 + type.getName(), e);%0A%09%09%09return Collections.emptyList();%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

support reading array values into objects in CommitInfoDetail