package com.bocloud.ims.entity.resource;

import com.bocloud.entity.annotations.Column;
import com.bocloud.entity.annotations.IgnoreAll;
import com.bocloud.entity.annotations.PK;
import com.bocloud.entity.annotations.Table;
import com.bocloud.entity.bean.GenericEntity;
import com.bocloud.entity.meta.PKStrategy;
import lombok.Data;

/**
 * 防火墙规则实体类
 *
 * @author wangyu
 * @version 1.0
 * @since 2017年8月29日
 */
@Table("firewall_rule")
@Data
public class FirewallRule extends GenericEntity {

	@PK(PKStrategy.AUTO)
	private Long id;// ID
	@Column("rule_uuid")
	private String ruleUuid;// 规则ID
	@Column("tenant_uuid")
	private String tenantUuid;// 租户ID
	@Column("policy_id")
	private Long policyId;// 绑定的策略ID
	@Column("policy_uuid")
	private String policyUuid;// 绑定的策略UUID
	@Column("is_shared")
	private Boolean shared;// 是否共享
	@Column("protocol")
	private String protocol;// 协议
	@Column("ip_version")
	private String ipVersion;// IP版本
	@Column("source_ip")
	private String sourceIp;// 源IP或子网(CIDR)
	@Column("vendor_type")
	private String vendorType;// 源IP或子网(CIDR)
	@Column("dest_ip")
	private String destIp;// 目的IP或子网(CIDR)
	@Column("source_port")
	private String sourcePort;// 源端口/端口范围(范围用":"分隔)
	@Column("dest_port")
	private String destPort;// 目的端口/端口范围(范围用":"分隔)
	@Column("position")
	private Integer position;// 该规则在与防火墙策略关联时,position为在策略中的位置，值从1开始,如果没有绑定任何策略,则值为null
	@Column("action")
	private String action;// 是否执行规则(ALLOW允许/DENY不允许/UNRECOGNIZED无法识别)
	@Column("is_enabled")
	private Boolean enabled;// 规则是否激活
	@Column("vendor_id")
	private Long vendorId;// 云平台ID
	@Column("tenant_id")
	private Long tenantId;// 租户ID
	@Column("project_id")
	private Long projectId;// 项目ID
	@IgnoreAll
	private String policyName;// 绑定的策略名称
	@IgnoreAll
	private String vendorName;
	@IgnoreAll
	private String tenantName;// 所属租户
	@IgnoreAll
	private String projectName;
	@IgnoreAll
	private String osTenantName;// openstack租户id

	@IgnoreAll
	private String type; // 是否前置 或 后置
	@IgnoreAll
	private String referRuleId; // 参照ruleId

	@Column("firewall_id")
	private Long firewallId;
	@Column("firewall_uuid")
	private String firewallUuid;


	// 深信服防火墙
	@Column("priority")
	private Integer priority;
	@Column("fw_index")
	private Integer index;
	@Column("is_default")
	private Boolean isDefault;
//	@Column("enable")
//	private Boolean enable;
	@Column("srv")
	private String srv;
	@Column("fw_range")
	private String range;
//	@Column("action")
//	private String action;


	@Column("srcip")
	private String srcip;
	@Column("dstip")
	private String dstip;
	@Column("src_type")
	private String srcType;
	@Column("dst_type")
	private String dstType;
	@Column("srcif_all")
	private Integer srcifAll;
	@Column("dstif_all")
	private Integer dstifAll;

	@IgnoreAll
	public Integer srvFlag;
	@IgnoreAll
	public String domainId;
	@IgnoreAll
	public String srcVm;
	@IgnoreAll
	public String dstVm;
	@IgnoreAll
	public String srcipg;
	@IgnoreAll
	public String dstipg;

	//v6.8
	@Column("policy_type")
	private String policyType;
	@Column("sangfor_project_id")
	private String sangforProjectId;
	@Column("rule_ids")
	private String ruleIds;
	@Column("network_type")
	private String networkType;
	@Column("sangfor_policy_id")
	private String sangforPolicyId;
	@Column("vpc_id")
	private String vpcId;

	@Column("az_id")
	private String azId;

	@IgnoreAll
	private String azName;



	public FirewallRule() {
		super();
	}

	public void preSave(Long creatorId, Long menderId, Long vendorId, Long tenantId, Long projectId) {
		this.setCreatorId(creatorId);
		this.setMenderId(menderId);
		this.setVendorId(vendorId);
		this.setTenantId(tenantId);
		this.setProjectId(projectId);
	}

	/**
	 * @param ruleUuid
	 * @param tenantUuid
	 * @param policyId
	 * @param policyUuid
	 * @param shared
	 * @param protocol
	 * @param ipVersion
	 * @param sourceIp
	 * @param destIp
	 * @param sourcePort
	 * @param destPort
	 * @param position
	 * @param action
	 * @param enabled
	 * @param vendorId
	 */
	public FirewallRule(String ruleUuid, String tenantUuid, Long policyId, String policyUuid, Boolean shared,
			String protocol, String ipVersion, String sourceIp, String destIp, String sourcePort, String destPort,
			Integer position, String action, Boolean enabled, Long vendorId) {
		super();
		this.ruleUuid = ruleUuid;
		this.tenantUuid = tenantUuid;
		this.policyId = policyId;
		this.policyUuid = policyUuid;
		this.shared = shared;
		this.protocol = protocol;
		this.ipVersion = ipVersion;
		this.sourceIp = sourceIp;
		this.destIp = destIp;
		this.sourcePort = sourcePort;
		this.destPort = destPort;
		this.position = position;
		this.action = action;
		this.enabled = enabled;
		this.vendorId = vendorId;
	}


}
