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.Generic;
import com.bocloud.entity.meta.PKStrategy;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * 资源配额类
 *
 * @author wangyu
 * @since 2017年7月4日
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table("resource_quota")
@EqualsAndHashCode(callSuper = true)
public class ResourceQuota extends Generic {

	@PK(value = PKStrategy.AUTO)
	private Long id;// id
	@Column("target")
	private Long target;// 租户ID
	@Column("catalog")
	private Catalog catalog;// 账号类别
	@Column("quota")
	private Long quota;// 总配额
	@Column("assigned")
	private Long assigned;// 已分配
	@Column("used")
	private Long used;// 已使用
	@Column("unit")
	private String unit;// 单位
	@Column("code")
	private String code;// 配额类型
	@Column("category")
	private Category category;// 配额类型
	@IgnoreAll
	private Long oldQuota;// 旧配额
	@IgnoreAll
	private Long minQuota;// 最小配额数
	@IgnoreAll
	private Long maxQuota;// 最大配额数
	@IgnoreAll
	private String tenantName;// 租户名称
	@IgnoreAll
	private Boolean releasable; // 资源配额是否可释放
	@IgnoreAll
	private String name;// 配额名称
	@IgnoreAll
	private Long quotaActionValue;// 配额操作值
	@IgnoreAll
	private Long sn;// 排序序号

	public ResourceQuota(Long target, Catalog catalog, Long quota, Long used, String code, Category category) {
		this.target = target;
		this.catalog = catalog;
		this.quota = quota;
		this.used = used;
		this.code = code;
		this.category = category;
	}

	public ResourceQuota(Long target, Catalog catalog, Long quota, Long assigned, Long used, String unit, String code,
			Category category, Long minQuota, Long maxQuota, String name) {
		this.target = target;
		this.catalog = catalog;
		this.quota = quota;
		this.assigned = assigned;
		this.used = used;
		this.unit = unit;
		this.code = code;
		this.category = category;
		this.minQuota = minQuota;
		this.maxQuota = maxQuota;
		this.name = name;
	}

	public ResourceQuota(Long target, Catalog catalog, Long quota, Long used, Long assigned, String unit, String code,
			Category category) {
		this.target = target;
		this.catalog = catalog;
		this.quota = quota;
		this.used = used;
		this.assigned = assigned;
		this.code = code;
		this.unit = unit;
		this.category = category;
	}

	public ResourceQuota(String code, Long quotaActionValue) {
		this.code = code;
		this.quotaActionValue = quotaActionValue;
	}

	/**
	 * 配额对象类型
	 */
	public enum Catalog {
		/**
		 * 租户配额
		 */
		TENANT,
		/**
		 * 项目配额
		 */
		PROJECT,
	}

	/**
	 * 配额类型
	 */
	public enum Category {
		/**
		 * 服务配额
		 */
		Service,
		/**
		 * 资源配额
		 */
		Meta,
	}

	public enum Action {
		/**
		 * 分出(分配量增加)
		 */
		Distribute,
		/**
		 * 分得(总量增加)
		 */
		Assign,
		/**
		 * 订购(使用增加)
		 */
		Order,
		/**
		 * 减配(总量减少)
		 */
		Decrease,
		/**
		 * 释放(分配减少)
		 */
		Release,
		/**
		 * 回滚
		 */
		Callback,
	}
}
