package com.bocloud.ims.entity.resource.kubernetes;

import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;

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.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import lombok.Data;

/**
 * k8s容器组
 *
 * @author weiwei
 */
@Table("kube_pod")
@Data
public class KubePod extends GenericEntity {

	@PK(value = PKStrategy.AUTO)
	private Long id; // ID
	@Column("instance_id")
	private String instanceId;// 实例ID
	@Column("pod_ip")
	private String podIp;// 地址
	@Column("labels")
	private String labels;
	@Column("ns_id")
	private Long nsId; // 命名空间ID
	@Column("ns_name")
	private String namespace;
	@Column("node_id")
	private Long nodeId; // 节点ID
	@Column("node_name")
	private String nodeName;
	@Column("service_id")
	private Long serviceId; // 服务ID
	@Column("service_name")
	private String serviceName;
	@Column("vendor_id")
	private Long vendorId; // 云供应商Id
	@Column("yaml_text")
	private String yamlText;
	@Column("deployment_name")
	private String deploymentName;
	@Column("deployment_uid")
	private String deploymentUid;
	@Column("deployment_api_version")
	private String deploymentApiVersion;
	@Column("tenant_id")
	private Long tenantId;
	@Column("project_id")
	private Long projectId;// 项目ID
	@Column("uid")
	private String uid;
	@Column("app_id")
	private Long appId;
	@Column("app_name")
	private String appName;
	@Column("kind")
	private String kind;
	@Column("api_version")
	private String apiVersion;
	@Column("image_name")
	private String imageName;
	
	@Column("creation_time")
	@JsonSerialize(using = com.bocloud.common.utils.DateSerializer.class)
	@JsonDeserialize(using = com.bocloud.common.utils.DateDeserializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date creationTime;

	// 用于csp
	@IgnoreAll
	private String thresholdGroupName;// 阈值组
	@IgnoreAll
	private String policyName;// 分发策略
	@IgnoreAll
	private Long ruleRelationId;// 关联关系id
	@IgnoreAll
	private String tenantName;// 所属租户
	@IgnoreAll
	private Long thresholdGroupId; // 阈值组ID
	@IgnoreAll
	private Long policyId; // 分发策略ID
	@IgnoreAll
	private String projectVisibility;

	@Column("parent_resource_uid")
	private String parentResourceUid;
	@Column("parent_resource_type")
	private String parentResourceType;
	@Column("parent_resource_name")
	private String parentResourceName;
	@Column("parent_resource_version")
	private String parentResourceVersion;

	public void preSave(Long creatorId, Long menderId, Long vendorId, Long nodeId, Long nsId) {
		this.setCreatorId(creatorId);
		this.setMenderId(menderId);
		this.setVendorId(vendorId);
		this.setNodeId(nodeId);
		this.setNsId(nsId);
	}

}
