package com.rjconsultores.ventaboletos.entidad;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import br.com.rjconsultores.auditador.annotations.NaoAuditar;
import br.com.rjconsultores.auditador.interfaces.Auditavel;

@Entity
@SequenceGenerator(name = "DIVISION_SEQ", sequenceName = "DIVISION_SEQ", allocationSize = 1)
@Table(name = "DIVISION")
public class Division implements Serializable, Auditavel<Division> {

	private static final long serialVersionUID = 1L;
	@Id
	@Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "DIVISION_SEQ")
	@Column(name = "DIVISION_ID")
	private Integer divisionId;
	
	@Column(name = "NOMBDIVISION")
	private String nombDivion;
	@OneToOne
	@JoinColumn(name = "EMPRESA_ID")
	private Empresa empresa;
	@Column(name = "ACTIVO")
	private Boolean activo;
	@Column(name = "FECMODIF")
	@Temporal(TemporalType.TIMESTAMP)
	private Date fecmodif;
	@Column(name = "USUARIO_ID")
	private Integer usuarioId;
	
	@Transient
	@NaoAuditar
	private Division divisionClone;

	public Division() {

	}

	public Division(Integer divisionId) {
		this.divisionId = divisionId;
	}

	public Integer getDivisionId() {
		return divisionId;
	}

	public void setDivisionId(Integer divisionId) {
		this.divisionId = divisionId;
	}

	public String getNombDivion() {
		return nombDivion;
	}

	public void setNombDivion(String nombDivion) {
		this.nombDivion = nombDivion;
	}

	public Empresa getEmpresa() {
		return empresa;
	}

	public void setEmpresa(Empresa empresa) {
		this.empresa = empresa;
	}

	public Boolean getActivo() {
		return activo;
	}

	public void setActivo(Boolean activo) {
		this.activo = activo;
	}

	public Date getFecmodif() {
		return fecmodif;
	}

	public void setFecmodif(Date fecmodif) {
		this.fecmodif = fecmodif;
	}

	public Integer getUsuarioId() {
		return usuarioId;
	}

	public void setUsuarioId(Integer usuarioId) {
		this.usuarioId = usuarioId;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((divisionId == null) ? 0 : divisionId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Division))
			return false;
		Division other = (Division) obj;
		if (getDivisionId() == null) {
			if (other.getDivisionId() != null)
				return false;
		} else if (!getDivisionId().equals(other.getDivisionId()))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.getNombDivion();
	}

	@Override
	public void clonar() throws CloneNotSupportedException {
		divisionClone = new Division();
		divisionClone = (Division) this.clone();
	}

	@Override
	public Division getCloneObject() {
		return divisionClone;
	}

	@Override
	public String getTextoInclusaoExclusao() {
		return String.format("ID [%s]", getDivisionId());
	}

}
