/**
 * addr2 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.common.dto;

import java.io.Serializable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 * @author 田平 create 2020年4月10日下午1:10:54
 *
 */
@ApiModel(description = "服务实例")
@Getter
@Setter
@ToString
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
public class ServiceInst implements Serializable {
	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "满足前端需求的ID，无实际意义")
	private int instId;

	@ApiModelProperty(value = "实例组，例如工作流，接口，应用 default,workflow,intf,service")
	private String group;

	@ApiModelProperty(value = "spring.application.name属性,相同的组appName不能相同")
	private String appName;

	@ApiModelProperty(value = "主机地址")
	private String host;

	@ApiModelProperty(value = "主机端口")
	private int port;

	@ApiModelProperty(value = "灰度版本号")
	private String apiVersion;

	public static String getPrefix(String group, String appName) {
		StringBuilder sb = new StringBuilder();
		return sb.append("/").append(group)
				.append("/").append(appName)
				.append("/").toString();
	}

	public String getProxyPrefix() {
		return getPrefix(this.group, this.appName);
	}

	public String getAddr() {
		return "[" + this.host + ":" + this.port + "]";
	}

}
