package com.bocloud.ims.entity.resource;

import com.bocloud.cmp.model.SubnetModel;
import com.bocloud.common.model.RequestContext.Catalog;
import com.bocloud.common.utils.DaySerializer;
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 com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 阿里云vpc专用网络
 *
 * @author wangyu
 * @version 1.0
 * @since 2018年2月2日
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Table("vpc")
public class Vpc extends GenericEntity {

	@PK(PKStrategy.AUTO)
	private Long id;// ID
	@Column("router_id")
	private Long routerId;// 路由ID
	@Column("region_id")
	private String regionId;// 所属域
	@Column("cidr")
	private String cidr;// cidr
	@Column("ipv6_cidr")
	private String ipv6Cidr;// ipv6Cidr
	@Column("vswitch_ids")
	private String vswitchIds;// 交换机ID
	@Column("vpc_id")
	private String vpcId;// 专用网络ID
	@Column("user_cidrs")
	private String userCidrs;// 用户cidr
	@Column("default_vpc")
	private Boolean defaultVpc;// 是否为默认vpc
	@Column("vendor_id")
	private Long vendorId;// 所属云平台
	@Column("tenant_id")
	private Long tenantId;// 租户ID
	@Column("project_id")
	private Long projectId;// 项目ID
	@Column("azure_resource_group_name")
	private String azureResourceGroupName; // azure 资源组名称
	@Column("resource_group_id")
	private Long resourceGroupId;
	@Column("network_id")
	private Long networkId;// 网络id
	@Column("uuid")
	private String uuid;// uuid，对应子订单号
	@Column("catalog")
	private Catalog catalog;// 账号类别
	@IgnoreAll
	private String regionName;
	@IgnoreAll
	private String tenantName;
	@IgnoreAll
	private String projectName;
	@IgnoreAll
	private String projectVisibility;
	@IgnoreAll
	private String vendorType;
	@IgnoreAll
	private String vendorName;
	@IgnoreAll
	private List<SecurityGroup> securityGroups;
	@IgnoreAll
	private List<Subnet> subnets;
	@IgnoreAll
	private List<SubnetModel> subnetModels;
	@IgnoreAll
	private List<Integer> fabricPoolIds; // 该VPC包含的Fabric池id列表
	@IgnoreAll
	private Integer serverCount;//云主机总数
	@IgnoreAll
	private Integer subnetCount;//关联子网总数
	@IgnoreAll
	private Integer routeTableCount;//关联路由表总数
	@IgnoreAll
	private Integer loadBalancerCount;//关联负载均衡总数
	@IgnoreAll
	private Integer networkCardCount;//关联弹性网卡总数
	@IgnoreAll
	private List<Map> includeResources;//包含资源



	@Column("expired_time")
	@JsonSerialize(using = DaySerializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date expiredTime;// 过期时间
	@Column("business_id")
	private Long businessId;
	
	@Column("resource_group_uuid")
	private String resourceGroupUuid; // 资源组ID
	@IgnoreAll
	private String resourceGroupName;
	@Column("router_uuid")
	private String routerUuid;// 路由ID
	@IgnoreAll
	private Boolean providedIpv6Cidr;
	@Column("ddos_plan_uuid")
	private String ddosPlanUuid;
	@Column("ddos_plan_id")
	private Long ddosPlanId;
	@Column("ddos_plan_enabled")
	private Boolean ddosPlanEnabled;
	
	@Column("pool_group_id")
	private Long poolGroupId;

	/**
	 * @param routerId
	 * @param regionId
	 * @param cidr
	 * @param vswitchIds
	 * @param vpcId
	 * @param userCidrs
	 * @param defaultVpc
	 * @param vendorId
	 */
	public Vpc(Long routerId, String regionId, String cidr, String vswitchIds, String vpcId, String userCidrs,
			Boolean defaultVpc, Long vendorId) {
		super();
		this.routerId = routerId;
		this.regionId = regionId;
		this.cidr = cidr;
		this.vswitchIds = vswitchIds;
		this.vpcId = vpcId;
		this.userCidrs = userCidrs;
		this.defaultVpc = defaultVpc;
		this.vendorId = vendorId;
	}

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