/*
 * Arrebol Consultancy copyright.
 * 
 * This code belongs to Arrebol Consultancy
 * its use, redistribution or modification are prohibited 
 * without written authorization from Arrebol Consultancy.
 */
package com.arrebol.apc.model.loan;

import com.arrebol.apc.model.core.User;
import com.arrebol.apc.model.enums.LoanStatus;
import com.arrebol.apc.model.enums.OwnerLoan;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
@Entity
@Table(name = "APC_LOAN_BY_USER")
public class LoanByUser implements Serializable {

    private static final long serialVersionUID = 6101775548154917785L;

    @EmbeddedId
    private LoanByUserId id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(
            name = "id_loan",
            referencedColumnName = "id",
            insertable = false,
            updatable = false
    )
    private Loan loan;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(
            name = "id_user",
            referencedColumnName = "id",
            insertable = false,
            updatable = false
    )
    private User user;

    @Enumerated(EnumType.STRING)
    @Column(name = "loan_by_user_status", nullable = false)
    private LoanStatus loanByUserStatus;

    @Column(name = "order_in_list")
    private Integer orderInList;

    @Column(name = "comments", length = 150)
    private String comments;

    @Enumerated(EnumType.STRING)
    @Column(name = "owner_loan", nullable = false)
    private OwnerLoan ownerLoan;

    @Column(name = "created_by", nullable = false, length = 36)
    private String createdBy;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_on", length = 19)
    private Date createdOn;

    public LoanByUser() {
    }

    /**
     *
     * @param id
     * @param loanByUserStatus
     * @param ownerLoan
     * @param createdBy
     */
    public LoanByUser(LoanByUserId id, LoanStatus loanByUserStatus, OwnerLoan ownerLoan, String createdBy) {
        this.id = id;
        this.loanByUserStatus = loanByUserStatus;
        this.ownerLoan = ownerLoan;
        this.createdBy = createdBy;
        this.createdOn = new Date();
    }

    /**
     *
     * @param id
     * @param orderInList
     */
    public LoanByUser(LoanByUserId id, Integer orderInList) {
        this.id = id;
        this.orderInList = orderInList;
    }

    public LoanByUserId getId() {
        return id;
    }

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

    public Loan getLoan() {
        return loan;
    }

    public void setLoan(Loan loan) {
        this.loan = loan;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public LoanStatus getLoanByUserStatus() {
        return loanByUserStatus;
    }

    public void setLoanByUserStatus(LoanStatus loanByUserStatus) {
        this.loanByUserStatus = loanByUserStatus;
    }

    public Integer getOrderInList() {
        return orderInList;
    }

    public void setOrderInList(Integer orderInList) {
        this.orderInList = orderInList;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public OwnerLoan getOwnerLoan() {
        return ownerLoan;
    }

    public void setOwnerLoan(OwnerLoan ownerLoan) {
        this.ownerLoan = ownerLoan;
    }

    public String getCreatedBy() {
        return createdBy;
    }

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

    public Date getCreatedOn() {
        return createdOn;
    }

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

}
