/*
 * 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.ComissionType;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
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.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;

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

    private static final long serialVersionUID = 7580350030712936070L;

    @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_user",
            referencedColumnName = "id",
            nullable = false
    )
    private User user;

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

    @Column(name = "amount", nullable = false)
    private BigDecimal amount;

    @Enumerated(EnumType.STRING)
    @Column(name = "comission")
    private ComissionType comission;

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

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

    public Delivery() {
    }

    /**
     *
     * @param user
     * @param loan
     * @param amount
     * @param createdBy
     * @param createdOn
     */
    public Delivery(User user, Loan loan, BigDecimal amount, String createdBy, Date createdOn) {
        this.user = user;
        this.loan = loan;
        this.amount = amount;
        this.createdBy = createdBy;
        this.createdOn = createdOn;
    }

    /**
     *
     * @param user
     * @param loan
     * @param amount
     * @param createdBy
     * @param createdOn
     * @param comission
     */
    public Delivery(User user, Loan loan, BigDecimal amount, String createdBy, Date createdOn, ComissionType comission) {
        this.user = user;
        this.loan = loan;
        this.amount = amount;
        this.createdBy = createdBy;
        this.createdOn = createdOn;
        this.comission = comission;
    }

    public String getId() {
        return id;
    }

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

    public User getUser() {
        return user;
    }

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

    public Loan getLoan() {
        return loan;
    }

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

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public ComissionType getComission() {
        if (null == comission) {
            comission = ComissionType.INCLUDED;
        }
        return comission;
    }

    public void setComission(ComissionType comission) {
        this.comission = comission;
    }

    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;
    }

    @Override
    public String toString() {
        return "Delivery{" + "user=" + user + ", createdOn=" + createdOn + '}';
    }

}
