package com.bocloud.ims.entity.resource;

import com.bocloud.common.utils.DateDeserializer;
import com.bocloud.common.utils.DateSerializer;
import com.bocloud.entity.annotations.*;
import com.bocloud.entity.bean.Generic;
import com.bocloud.entity.meta.PKStrategy;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigInteger;
import java.util.Date;

import static java.math.BigInteger.*;

/**
 * 
 * @description IP管理
 * @version 5.1.0
 * @author wangyu
 * @date: 2020-11-30
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@Table("ip")
public class Ip extends Generic {
	/**
	 * ID
	 */
	@PK(value = PKStrategy.AUTO)
	private Long id;
	/**
	 * IP地址
	 */
	@Column("ip")
	private String ip;
	/**
	 * 网关
	 */
	@Column("gateway")
	private String gateway;
	/**
	 * DNS
	 */
	@Column("dns")
	private String dns;
	/**
	 * 掩码
	 */
	@Column("mask")
	private String mask;
	/**
	 * 平台ID
	 */
	@Column("vendor_id")
	private Long vendorId;
	/**
	 * IP池id
	 */
	@Column("pool_id")
	private Long poolId;
	/**
	 * 资源ID
	 */
	@Column("resource_id")
	private String resourceId;
	/**
	 * 目标ID
	 */
	@Column("target")
	private Long target;
	/**
	 * 目标类型
	 */
	@Column("catalog")
	private String catalog;
	/**
	 * 网络ID
	 */
	@Column("network_id")
	private Long networkId;
	/**
	 * 子网ID
	 */
	@Column("subnet_id")
	private Long subnetId;
	/**
	 * IP状态
	 */
	@Column("status")
	private IpStatus status;
	/**
	 * 备注
	 */
	@Column("remark")
	private String remark;
	/**
	 * 创建时间
	 */
	@IgnoreUpdate
	@Column(value = "gmt_create", nullable = false)
	@JsonSerialize(using = DateSerializer.class)
	@JsonDeserialize(using = DateDeserializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date gmtCreate;
	/**
	 * 网络名称
	 */
	@IgnoreAll
	private String networkName;
	/**
	 * 子网名称
	 */
	@IgnoreAll
	private String subnetName;
	/**
	 * 平台名称
	 */
	@IgnoreAll
	private String vendorName;
	/**
	 * IP绑定目标名称
	 */
	@IgnoreAll
	private String targetName;
	/**
	 * IP对应ip池名称
	 */
	@IgnoreAll
	private String poolName;


	public Ip(String ip, String mask, String gateway, String dns, Long vendorId, String resourceId, Long poolId,
			IpStatus status) {
		super();
		this.ip = ip;
		this.mask = mask;
		this.gateway = gateway;
		this.dns = dns;
		this.vendorId = vendorId;
		this.resourceId = resourceId;
		this.poolId = poolId;
		this.status = status;
	}

	/**
	 * 
	 * IP状态枚举
	 * @version 5.1.0
	 * @author wangyu
	 * @date: 2020-11-30
	 *
	 */
	public enum IpStatus {
		/**
		 * 空闲
		 */
		free,
		/**
		 * 已使用
		 */
		used,
		/**
		 * 已锁定
		 */
		lock,
		/**
		 * 预占
		 */
		preempt
	}

}
