package com.ctrip.xpipe.redis.core.entity;

import java.util.Objects;

/**
 * used for trans info between meta server and keeper container
 * @author wenchao.meng
 *
 * Aug 2, 2016
 */
public class KeeperTransMeta {

	public enum KeeperReplType {
		REPL_DEFAULT(false),
		REPL_HYTERO(true);

		private final boolean supportGtidSet;
		KeeperReplType(boolean supportGtidSet) {
			this.supportGtidSet = supportGtidSet;
		}

		public boolean supportGtidSet() {
			return supportGtidSet;
		}

		public static KeeperReplType defaultType() {
			return REPL_DEFAULT;
		}
	}

	private Long clusterDbId;

	private Long shardDbId;
	
	private KeeperMeta keeperMeta;

	private KeeperReplType keeperReplType = KeeperReplType.defaultType();

	//for json conversion
	public KeeperTransMeta() {}

	public KeeperTransMeta(Long clusterDbId, Long shardDbId, KeeperReplType keeperReplType, KeeperMeta keeperMeta) {
		this.clusterDbId = clusterDbId;
		this.shardDbId = shardDbId;
		this.keeperReplType = keeperReplType;
		this.keeperMeta = keeperMeta;
	}

	public KeeperTransMeta(Long clusterDbId, Long shardDbId, KeeperMeta keeperMeta) {
		this(clusterDbId, shardDbId, KeeperReplType.defaultType(), keeperMeta);
	}

	public KeeperMeta getKeeperMeta() {
		return keeperMeta;
	}

	public void setKeeperMeta(KeeperMeta keeperMeta) {
		this.keeperMeta = keeperMeta;
	}

	public Long getClusterDbId() {
		return clusterDbId;
	}

	public void setClusterDbId(Long clusterDbId) {
		this.clusterDbId = clusterDbId;
	}

	public Long getShardDbId() {
		return shardDbId;
	}

	public void setShardDbId(Long shardDbId) {
		this.shardDbId = shardDbId;
	}

	public KeeperReplType getKeeperReplType() {
		return keeperReplType;
	}

	public void setKeeperReplType(KeeperReplType keeperReplType) {
		this.keeperReplType = keeperReplType;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		KeeperTransMeta that = (KeeperTransMeta) o;
		return Objects.equals(clusterDbId, that.clusterDbId) &&
				Objects.equals(shardDbId, that.shardDbId) &&
				Objects.equals(keeperMeta, that.keeperMeta) &&
				keeperReplType == that.keeperReplType;
	}

	@Override
	public int hashCode() {
		return Objects.hash(clusterDbId, shardDbId, keeperMeta, keeperReplType);
	}

	@Override
	public String toString() {
		return String.format("[%d,%d-%s:%d-%s]", clusterDbId, shardDbId, keeperMeta.getIp(), keeperMeta.getPort(), keeperReplType);
	}
}

@@ -214,358 +214,8 @@
  %7B%0A%0A
-%09public enum KeeperReplType %7B%0A%09%09REPL_DEFAULT(false),%0A%09%09REPL_HYTERO(true);%0A%0A%09%09private final boolean supportGtidSet;%0A%09%09KeeperReplType(boolean supportGtidSet) %7B%0A%09%09%09this.supportGtidSet = supportGtidSet;%0A%09%09%7D%0A%0A%09%09public boolean supportGtidSet() %7B%0A%09%09%09return supportGtidSet;%0A%09%09%7D%0A%0A%09%09public static KeeperReplType defaultType() %7B%0A%09%09%09return REPL_DEFAULT;%0A%09%09%7D%0A%09%7D%0A%0A
 %09pri
@@ -302,80 +302,8 @@
 a;%0A%0A
-%09private KeeperReplType keeperReplType = KeeperReplType.defaultType();%0A%0A
 %09//f
@@ -412,39 +412,8 @@
 bId,
- KeeperReplType keeperReplType,
  Kee
@@ -515,226 +515,25 @@
 eper
-ReplType = keeperReplType;%0A%09%09this.keeperMeta = keeperMeta;%0A%09%7D%0A%0A%09public KeeperTransMeta(Long clusterDbId, Long shardDbId, KeeperMeta keeperMeta) %7B%0A%09%09this(clusterDbId, shardDbId, KeeperReplType.defaultType(), keeperMeta)
+Meta = keeperMeta
 ;%0A%09%7D
@@ -964,190 +964,8 @@
 %09%7D%0A%0A
-%09public KeeperReplType getKeeperReplType() %7B%0A%09%09return keeperReplType;%0A%09%7D%0A%0A%09public void setKeeperReplType(KeeperReplType keeperReplType) %7B%0A%09%09this.keeperReplType = keeperReplType;%0A%09%7D%0A%0A
 %09@Ov
@@ -1301,53 +1301,8 @@
 eta)
- &&%0A%09%09%09%09keeperReplType == that.keeperReplType
 ;%0A%09%7D
@@ -1395,32 +1395,16 @@
 eperMeta
-, keeperReplType
 );%0A%09%7D%0A%0A%09
@@ -1552,24 +1552,8 @@
 rt()
-, keeperReplType
 );%0A%09

remove keeper type from KeeperTransMeta