package com.bocloud.ims.entity.resource;

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.Data;
import org.springframework.format.annotation.DateTimeFormat;

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

/**
 * 镜像实体类
 *
 * @author DZG
 * @since V1.0 2016年9月13日
 */
@Table("image")
@Data
public class Image extends GenericEntity {

	@PK(value = PKStrategy.AUTO)
	private Long id; // ID
	@Column("os_type")
	private String osType;// 镜像格式
	@Column("os_name")
	private String osName; // OS名称
	@Column("os_version")
	private String osVersion; // OS版本名称
	@Column("os_category")
	private String osCategory;// 操作系统
	@Column("size")
	private Double size;// 容量
	@Column("min_disk")
	private Long minDisk;// 作为系统的容量
	@Column("kernel_version")
	private String kernelVersion;// 内核版本
	@Column("vendor_id")
	private Long vendorId; // 云供应商ID
	@Column("vendor_type")
	private String vendorType;// 镜像类型
	@Column("image_uuid")
	private String imageUuid; // 镜像ID
	@Column("architecture")
	private String architecture; // 系统位数
	@Column("template_id")
	private Long templateId;// 模板ID
	@Column("catalog")
	private String catalog;// 分类
	@Column("icon_id")
	private Long iconId;
	@Column("file_path")
	private String filePath;// 本地上传路径
	@Column("qga_installed")
	private Boolean qgaInstalled;// 是否安装了hw_qemu_guest_agent
	@Column("store_id")
	private Long storeId;// 数据存储ID
	@Column("default_user")
	private String defaultUser;// 默认用户
	@Column("tenant_id")
	private Long tenantId;// 租户ID
	@Column("project_id")
	private Long projectId;
	@Column("region_id")
	private String regionId;
	@Column("region")
	private Long region;
	@Column("image_label")
	private String imageLabel;// 镜像标签
	@Column("image_type")
	private String imageType;
	@Column("iso_name")
	private String isoName;// 物理镜像的文件名
	@Column("azure_resource_group_name")
	private String azureResourceGroupName; // azure 资源组名称
	@Column("offer")
	private String offer;
	@Column("sku")
	private String sku;
	@Column("publisher")
	private String publisher;
	@IgnoreAll
	private String diskFormat;
	@IgnoreAll
	private CloudServer server;
	@IgnoreAll
	private String tenantName;// 租户名称
	@IgnoreAll
	private String projectName;// 项目名称
	@IgnoreAll
	private String projectVisibility;
	@IgnoreAll
	private String targetName;// 租户用户
	@IgnoreAll
	@JsonSerialize(using = DaySerializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date expiredTime;// 过期时间
	@Column("tenant_uuid")
	private String tenantUuid;// openstack底层租户id
	@IgnoreAll
	private String osTenantName;// OpenStack底层租户名称
	@IgnoreAll
	private Long serverId;// 虚拟机ID
	@IgnoreAll
	private String vendorName; // 云供应商名称
	@IgnoreAll
	private String icon;// 应用图标
	@IgnoreAll
	private String regionName; // 镜像所在区域名称
	@IgnoreAll
	private String instanceId;
	@IgnoreAll
	private List<Long> volumeIds;
	@IgnoreAll
	private List<Volume> volumes; // 镜像挂载的卷
	/**
	 * 镜像网卡列表
	 */
	@IgnoreAll
	private List<NetworkCard> networkCards;
	@IgnoreAll
	private String imageSource; // 判断镜像是通过哪种方式创建的，虚拟机制作镜像和上传镜像
	@IgnoreAll
	private Boolean isNoRestart;
	
	@Column("block_device_mappings")
	private Object blockDeviceMappings; // 区块设备映射
	@Column("root_device_name")
	private String rootDeviceName; // 根设备名称
	@Column("root_device_type")
	private String rootDeviceType; // 根设备类型
	@Column("resource_group_uuid")
	private String resourceGroupUuid;//资源组编号
	@Column("support")
	private String support;
	@Column("virtual_env_type")
	private String virtualEnvType;
	@IgnoreAll
	private String type;

	public Image() {
		super();
	}

	public Image(String name, String osType, String osVersion, Double size, String isoName, String status,
			String remark) {
		super();
		this.setName(name);
		this.osType = osType;
		this.osVersion = osVersion;
		this.size = size;
		this.setStatus(status);
		this.isoName = isoName;
		this.setRemark(remark);
	}

	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);
	}

}
