/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arrebol.taxiservicios.model.predio;



import com.arrebol.taxiservicios.model.catalog.Location;
import com.arrebol.taxiservicios.model.core.Person;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.CompromisoPago;
import com.arrebol.taxiservicios.model.enums.GenericEnumType;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;

/**
 *
 * @author Picasso
 */
@Entity
@Table(name = "manzana")
public class Manzana implements Serializable {

    private static final long serialVersionUID = -6653037938225719593L;

    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "id", length = 36)
    private String id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(
            name = "id_proyecto",
            referencedColumnName = "id",
            nullable = false
    )
    private Predio predio;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "estatus_activo", nullable = true)
    private GenericEnumType estatusActivo;
    
    @Column(name = "nombre", nullable = false)
    private String  nombre;
    
    @Column(name = "num_lotes", nullable = false)
    private int numLotes;
 
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(
            name = "created_by",
            referencedColumnName = "id",
            nullable = false
    )
    private User createdBy;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_on", length = 19)
    private Date createdOn;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @JoinColumn(
            name = "last_updated_by",
            referencedColumnName = "id",
            nullable = true
    )
    private User lastUpdatedBy;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_updated_on", length = 19)
    private Date lastUpdatedOn;

    @OneToMany(
        mappedBy = "manzana",
        cascade = CascadeType.ALL,
        fetch = FetchType.LAZY,
        orphanRemoval = true
    )
    private List<Lote> lotes;

     /**
     *
     * @param id
     * @param predio
     * @param nombre
     */
    public Manzana(String id, Predio predio, String nombre) {
        this.id = id;
        this.predio = predio;
        this.nombre = nombre;
    }
    
    /**
     *
     * @param id
     * @param predio
     * @param nombre
     * @param lotes
     */
    public Manzana(String id, Predio predio, String nombre, List<Lote> lotes) {
        this.id = id;
        this.predio = predio;
        this.nombre = nombre;
        this.lotes = lotes;
    }
   
    public Manzana() {
    }

    public Manzana(String id) {
        this.id = id;
    }    

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

   
 

    public User getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

  
    
    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public User getLastUpdatedBy() {
        return lastUpdatedBy;
    }

    public void setLastUpdatedBy(User lastUpdatedBy) {
        this.lastUpdatedBy = lastUpdatedBy;
    }

    public Date getLastUpdatedOn() {
        return lastUpdatedOn;
    }

    public void setLastUpdatedOn(Date lastUpdatedOn) {
        this.lastUpdatedOn = lastUpdatedOn;
    }

    public Predio getPredio() {
        return predio;
    }

    public void setPredio(Predio predio) {
        this.predio = predio;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public int getNumLotes() {
        return numLotes;
    }

    public void setNumLotes(int numLotes) {
        this.numLotes = numLotes;
    }

    public GenericEnumType getEstatusActivo() {
        return estatusActivo;
    }

    public void setEstatusActivo(GenericEnumType estatusActivo) {
        this.estatusActivo = estatusActivo;
    }
    
    
    

    public List<Lote> getLotes() {
        return lotes;
    }

    public void setLotes(List<Lote> lotes) {
        this.lotes = lotes;
    }
    
    
    
    @Override
    public String toString() {
        return nombre;
    }

   

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Manzana other = (Manzana) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

}
