/*
 * Created on Jul 26, 2006
 * 
 * (C) Copyright TANDBERG Television Ltd.
 */

package com.tandbergtv.workflow.sanmanager.entities;

import java.io.Serializable;
import java.util.Date;

import org.apache.log4j.Logger;

/**
 * Maintains information about a Drive
 * 
 * @author Vijay Silva
 */
public class SANDrive implements Cloneable, Serializable
{
	// Serialization UID
	private static final long serialVersionUID = 7338412016673517462L;

	// Default ID when none is found in the configuration
	private static final int DEFAULT_ID = -1;

	private long id = DEFAULT_ID; 

	private String name;

	private String path;

	private int warningThreshold;

	private int errorThreshold;

	private long capacity;

	private long usedSpace;

	private DriveStatus status = DriveStatus.OK;

	private DriveCapacityUnit displayUnit = DriveCapacityUnit.GIGABYTE;
	
	private long configureDriveID = DEFAULT_ID; // internal drive id read from san configuration

	private Long resourceID = null;
	
	private String description = "";
	
	private static final Logger logger = Logger.getLogger(SANDrive.class);
	
	private Date sampleDate;

	/**
	 * Default Constructor
	 */
	public SANDrive()
	{
	}

	/**
	 * @return Returns the capacity (in BYTES).
	 */
	public long getCapacity()
	{
		return this.capacity;
	}

	/**
	 * @param capacity
	 *            The capacity to set (in BYTES).
	 */
	public void setCapacity(long capacity)
	{
		if (capacity < 0)
			capacity = 0;

		this.capacity = capacity;
	}

	/**
	 * @param unit
	 *            The Target unit in which to get the drive capacity value
	 * @return The capacity in the target unit.
	 */
	public double getCapacity(DriveCapacityUnit unit)
	{
		return DriveCapacityUnit.convert(this.capacity, DriveCapacityUnit.BYTE, unit);
	}

	/**
	 * @param capacity
	 *            The capacity to set.
	 * @param unit
	 *            The Unit of the capacity
	 */
	public void setCapacity(double capacity, DriveCapacityUnit unit)
	{
		if (capacity < 0)
			capacity = 0;

		this.capacity = (long) DriveCapacityUnit.convert(capacity, unit, DriveCapacityUnit.BYTE);
	}

	/**
	 * @return Returns the displayUnit.
	 */
	public DriveCapacityUnit getDisplayUnit()
	{
		return this.displayUnit;
	}

	/**
	 * @param displayUnit
	 *            The displayUnit to set.
	 */
	public void setDisplayUnit(DriveCapacityUnit displayUnit)
	{
		this.displayUnit = displayUnit;
	}

	/**
	 * Method to get the Capacity of the Drive in the Display Unit.
	 * 
	 * @return The Capacity value in the Display Unit
	 */
	public double getDisplayCapacity()
	{
		return DriveCapacityUnit.convert(this.capacity, DriveCapacityUnit.BYTE, this.displayUnit);
	}

	/**
	 * @return Returns the errorThreshold.
	 */
	public int getErrorThreshold()
	{
		return this.errorThreshold;
	}

	/**
	 * @param errorThreshold
	 *            The errorThreshold to set.
	 */
	public void setErrorThreshold(int errorThreshold)
	{
		this.errorThreshold = errorThreshold;
	}

	/**
	 * @return Returns the id.
	 */
	public long getId()
	{
		return this.id;
	}

	/**
	 * @param id
	 *            The id to set.
	 */
	public void setId(long id)
	{
		this.id = id;
	}

	/**
	 * @return Returns the name.
	 */
	public String getName()
	{
		return this.name;
	}

	/**
	 * @param name
	 *            The name to set.
	 */
	public void setName(String name)
	{
		this.name = name;
	}

	/**
	 * @return Returns the path.
	 */
	public String getPath()
	{
		return this.path;
	}

	/**
	 * @param path
	 *            The path to set.
	 */
	public void setPath(String path)
	{
		this.path = path;
	}

	/**
	 * @return Returns the status.
	 */
	public DriveStatus getStatus()
	{
		return this.status;
	}

	/**
	 * @param status
	 *            The status to set.
	 */
	public void setStatus(DriveStatus status)
	{
		this.status = status;
	}

	/**
	 * @return Returns the used space (in BYTES).
	 */
	public long getUsedSpace()
	{
		return this.usedSpace;
	}

	/**
	 * @param usedSpace
	 *            The usedSpace to set (in BYTES).
	 */
	public void setUsedSpace(long usedSpace)
	{
		this.usedSpace = usedSpace;
	}

	/**
	 * @return Returns the warningThreshold.
	 */
	public int getWarningThreshold()
	{
		return this.warningThreshold;
	}

	/**
	 * @param warningThreshold
	 *            The warningThreshold to set.
	 */
	public void setWarningThreshold(int warningThreshold)
	{
		this.warningThreshold = warningThreshold;
	}

	/**
	 * Method to clone the Drive
	 * 
	 * @see java.lang.Object#clone()
	 */
	@Override
	public Object clone()
	{
		SANDrive clone = null;

		try
		{
			clone = (SANDrive) super.clone();
		}
		catch (CloneNotSupportedException ex)
		{ // This should never happen
			logger.error("Failed to clone the SANDrive object.", ex);
		}

		return clone;
	}

	public long getConfigureDriveID() {
		return configureDriveID;
	}

	public void setConfigureDriveID(long configureDriveID) {
		this.configureDriveID = configureDriveID;
	}

	public Long getResourceID() {
		return resourceID;
	}

	public void setResourceID(Long resourceID) {
		this.resourceID = resourceID;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getSampleDate() {
		return sampleDate;
	}

	public void setSampleDate(Date sampleDate) {
		this.sampleDate = sampleDate;
	}
	
}
