package com.bocloud.ims.entity.resource;

import com.bocloud.cmp.model.ServerVolumeModel;
import com.bocloud.common.model.RequestContext.Catalog;
import com.bocloud.common.utils.DateSerializer;
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;

/**
 * 云硬盘实体类
 *
 * @author wangyu
 */
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Table("volume")
public class Volume extends GenericEntity {

	@PK(value = PKStrategy.AUTO)
	private Long id; // ID
	@Column("volume_uuid")
	private String volumeUuid; // 快设备ID
	@Column("size")
	private Integer size; // 大小
	@Column("vendor_id")
	private Long vendorId; // 云供应商ID
	@Column("region")
	private String region; // 卷所在区域
	@Column("type")
	private String type; // 类型
	@Column("boot_volume")
	private Boolean bootVolume;// 是否是作为系统盘的云硬盘
	@Column("category")
	private String category;// 型号
	@Column("delete_auto_snapshot")
	private Boolean deleteAutoSnapshot;// 自动删除快照
	@Column("delete_with_instance")
	private Boolean deleteWithInstance;// 随实例删除
	@Column("enable_auto_snapshot")
	private Boolean enableAutoSnapshot;//
	@Column("image_uuid")
	private String imageUuid; // 镜像ID
	@Column("instance_id")
	private String instanceId;// 实例ID
	@Column("zone")
	private String zone; // 区域
	@Column("source_snapshot_id")
	private String sourceSnapshotId;// 原快照ID
	@Column("request_id")
	private String requestId;
	@Column("server_id")
	private Long serverId; // 虚拟机ID
	@Column("device")
	private String device; // 挂载路径
	@Column("tenant_id")
	private Long tenantId;// 租户ID
	@Column("project_id")
	private Long projectId;
	@Column("disk_object_id")
	private String diskObjectId;// 硬盘对象唯一标识符
	
	@Column("expired_time")
	@JsonSerialize(using = DaySerializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date expiredTime;// 过期时间
	
	@Column("attached_time")
	@JsonSerialize(using = DateSerializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date attachedTime;// 挂载时间
	@Column("detached_time")
	@JsonSerialize(using = DateSerializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date detachedTime;// 解挂时间
	@Column("create_time")
	@JsonSerialize(using = DateSerializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;// 云硬盘的创建时间
	@Column("multiattach")
	private Boolean multiattach; // 是否为共享盘
	@Column("cloud_server_count")
	@IgnoreAll
	private Long cloudServerCount;
	@Column("image_count")
	@IgnoreAll
	private Long ImageCount;
	@Column("volume_type_id")
	private Long volumeTypeId;// 云硬盘类型Id
	@Column("volume_type")
	private String volumeType;// 云硬盘类型
	@Column("tenant_uuid")
	private String tenantUuid;// openstack底层项目UUID
	@Column("catalog")
	private Catalog Catalog;// 账号类别
	@Column("uuid")
	private String uuid;// uuid
	@Column("sku_id")
	private Long skuId;// skuId
	@Column("business_id")
	private Long businessId;
	
	@IgnoreAll
    private String userName;// 用户名称
    @IgnoreAll
    private String businessName;// 业务
    @IgnoreAll
    private String creatorName;// 创建者名称
    @IgnoreAll
    private String ownerName;// 所属人名称
    @IgnoreAll
    private String menderName;// 维护人名称
	
	@IgnoreAll
	private Integer countStatus;// 按照状态汇总
	@IgnoreAll
	private String vendorName; // 云供应商名称
	@IgnoreAll
	@Column("vendor_type")
	private String vendorType; // 云供应商名称
	@IgnoreAll
	private String regionName; // 镜像所在区域名称
	@IgnoreAll
	private String serverName; // 虚拟机名称
	@IgnoreAll
	private String tenantName;// 所属租户
	@IgnoreAll
	private String projectName;// 所属项目
	@IgnoreAll
	private String projectVisibility; // 项目类型
	@IgnoreAll
	private String targetName;// 租户用户
	@IgnoreAll
	private List<ServerVolumeModel> models;
	@IgnoreAll
	private String resourceGroupUuid;
	@IgnoreAll
	private String performanceLevel;

	@IgnoreAll
	private String zoneName;

	@Column("disk_expire_time")
	@JsonSerialize(using = DateSerializer.class)
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date diskExpireTime; // 过期时间
	@Column("disk_charge_type")
	private String diskChargeType; // 计费类型
	@Column("region_id")
	private String regionId;

	// 存储唯一标识
	@Column("data_store_id")
	private Long dataStoreId;

	// 存储名称
	@IgnoreAll
	private String dataStoreName;

	@Column("template_id")
	private Long templateId;
	@Column("template_name")
	@IgnoreAll
	private String templateName;
	@Column("storage_id")
	private Long storageId;
	@Column("storage_name")
	@IgnoreAll
	private String storageName;
	@Column("storage_uuid")
	@IgnoreAll
	private String storageUuid;
	@Column("storage_default_template_id")
	@IgnoreAll
	private Long storageDefaultTemplateId;

	@Column("backup_count")
	private String backupCount; // 备份数量
	@Column("vaults_uuid")
	private String vaultsUuid;

	@Column("block_count")
	private Long blockCount; // 卷block的数量
	@Column("block_size")
	private Double blockSize; // block的大小
	@Column("pool_id")
	private Long poolId; // volume_pool 表id
	@Column("pool_name")
	@IgnoreAll
	private String poolName; // volume_pool 表name
	@Column("sync_rate")
	private Integer syncRate; // 镜像同步速率
	@Column("udid")
	private String udid; // UDID (OpenVMS)
	@Column("compressed")
	private Boolean compressed; // 是否是压缩卷
	@Column("thinly_provisioned")
	private Boolean thinlyProvisioned; // 是否是精简卷
	@Column("identifier")
	private String identifier; // 卷标识
	@IgnoreAll
	private Integer storageHostCnt;
	@Column("key_path")
	private String keyPath; // smis传参用
	@Column("azure_resource_group_name")
	private String azureResourceGroupName; // azure 资源组名称
	@Column("resource_group_id")
	private Long resourceGroupId;
	@IgnoreAll
	private String resourceGroupName;
	@Column("operational_status")
	private String operationalStatus; // 运行状态
	@IgnoreAll
	private String groupNames;
	@IgnoreAll
	private String volumeTypeName;
	@Column("volume_Count")
	@IgnoreAll
	private Long volumeCount;
	@IgnoreAll
	private Integer inGroupCount;
	@Column("pool_free_capacity")
	@IgnoreAll
	private Double poolFreeCapacity;
	/**
	 * 监控相关
	 */
	@IgnoreAll
	private Long ruleRelationId;// 资源告警规则关联关系id
	@IgnoreAll
	private String thresholdGroupName;// 阈值组名称
	@IgnoreAll
	private String policyName;// 分发策略名称
	@IgnoreAll
	private Long thresholdGroupId; // 阈值组ID
	@IgnoreAll
	private Long policyId; // 分发策略ID
	@Column("allocated_size")
	private Double allocatedSize; // 已分配的容量
	@Column("snapshot_id")
	private Long snapshotId; // 存储卷的关联快照id
	@Column("synced_set_id")
	private Long syncedSetId; // 存储卷的所属一致性组id
	@Column("access_path_id")
	private Long accessPathId; // 存储卷的关联访问路径id
	@Column("qos_enabled")
	private Boolean qosEnabled; // 卷是否设置业务 QoS
	@Column("qos")
	private String qos;// 卷qos设置的参数
	@Column("performance_priority")
	private Long performancePriority; // 卷性能优先级
	@Column("migration_stripes")
	private Long migrationStripes; // 卷迁移速率级别
	@Column("sample")
	private String sample; // 卷性能数据
	@Column("access_path_name")
	@IgnoreAll
	private String accessPathName;
	@Column("synced_set_name")
	@IgnoreAll
	private String syncedSetName;
	@IgnoreAll
	private Integer snapshotCount;
	@Column("snapshot_name")
	@IgnoreAll
	private String snapshotName;
	@IgnoreAll
	private String osTenantName;
	@Column("iops")
	private Integer iops;// 磁盘每秒读写次数
	@Column("lvm_mntp")
	private String lvmMntp; // lvm挂载点
	@Column("force_mount")
	private Boolean forceMount; // 是否强制挂载
	@Column("file_system")
	private String fileSystem;// 文件系统
	@IgnoreAll
	private VolumeTemplate volumeTemplate;
	@IgnoreAll
	private String storeVal;
	@Column("for_use")
	private String forUse; // 用途，EMC存储在用

	@IgnoreAll
	private String callback;
	@IgnoreAll
	private String period;
	@IgnoreAll
	private Long sourceImgId;
	@IgnoreAll
	private Long sourceSnapId;
	@IgnoreAll
	private Long sourceValidId;
	@IgnoreAll
	private Long osType;

	public String getKeyPath() {
		return keyPath;
	}

	public void setKeyPath(String keyPath) {
		this.keyPath = keyPath;
	}

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

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