/*
 * 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.FeeStatus;
import com.arrebol.apc.model.enums.LoanDetailsType;
import com.arrebol.apc.model.enums.PeopleType;
import com.arrebol.apc.model.enums.TransferStatus;
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 javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.GenericGenerator;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
@Entity
@Table(name = "APC_LOAN_DETAIL",
        uniqueConstraints = {
           @UniqueConstraint(columnNames = {"id", "reference_number"}, name = "apc_loan_details_uk")
        })
public class LoanDetails implements Serializable {

   private static final long serialVersionUID = -6757564734339598051L;

   @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_loan",
           referencedColumnName = "id",
           nullable = false
   )
   private Loan loan;

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

   @Enumerated(EnumType.STRING)
   @Column(name = "people_type", nullable = false)
   private PeopleType peopleType;

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

   @Column(name = "reference_number")
   private Integer referenceNumber;

   @Enumerated(EnumType.STRING)
   @Column(name = "loan_details_type", nullable = false)
   private LoanDetailsType loanDetailsType;

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

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

   @Enumerated(EnumType.STRING)
   @Column(name = "fee_status")
   private FeeStatus feeStatus;

   @Enumerated(EnumType.STRING)
   @Column(name = "transfer_status")
   private TransferStatus transferStatus;

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

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

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

   @Transient
   private BigDecimal saldoInsoluto;

   public LoanDetails() {
   }

   /**
    *
    * @param id
    * @param createdOn
    * @param feeStatus
    */
   public LoanDetails(String id, Date createdOn, FeeStatus feeStatus) {
      this.id = id;
      this.createdOn = createdOn;
      this.feeStatus = feeStatus;
   }

   /**
    * Complete constructor.
    *
    * @param id
    * @param loan
    * @param peopleType
    * @param paymentAmount
    * @param loanDetailsType
    * @param comments
    * @param createdBy
    * @param createdOn
    */
   public LoanDetails(String id, Loan loan, PeopleType peopleType, BigDecimal paymentAmount, LoanDetailsType loanDetailsType, String comments, String createdBy, Date createdOn) {
      this.id = id;
      this.loan = loan;
      this.peopleType = peopleType;
      this.paymentAmount = paymentAmount;
      this.loanDetailsType = loanDetailsType;
      this.comments = comments;
      this.createdBy = createdBy;
      this.createdOn = createdOn;
   }

   /**
    *
    * @param id
    * @param loan
    * @param user
    * @param peopleType
    * @param referenceNumber
    * @param paymentAmount
    * @param loanDetailsType
    * @param comments
    * @param createdBy
    * @param createdOn
    */
   public LoanDetails(String id, Loan loan, User user, PeopleType peopleType, Integer referenceNumber, BigDecimal paymentAmount, LoanDetailsType loanDetailsType, String comments, String createdBy, Date createdOn) {
      this.id = id;
      this.loan = loan;
      this.user = user;
      this.peopleType = peopleType;
      this.referenceNumber = referenceNumber;
      this.paymentAmount = paymentAmount;
      this.loanDetailsType = loanDetailsType;
      this.comments = comments;
      this.createdBy = createdBy;
      this.createdOn = createdOn;
   }

   /**
    * Add new amount.
    *
    * @param loan
    * @param user
    * @param peopleType
    * @param paymentAmount
    * @param referenceNumber
    * @param loanDetailsType
    * @param createdBy
    * @param createdOn
    * @param comments
    */
   public LoanDetails(Loan loan, User user, PeopleType peopleType, BigDecimal paymentAmount, Integer referenceNumber, LoanDetailsType loanDetailsType, String createdBy, Date createdOn, String comments) {
      this.loan = loan;
      this.user = user;
      this.peopleType = peopleType;
      this.paymentAmount = paymentAmount;
      this.referenceNumber = referenceNumber;
      this.loanDetailsType = loanDetailsType;
      this.createdBy = createdBy;
      this.createdOn = createdOn;
      this.comments = comments;
   }

   /**
    * Add new amount.
    *
    * @param loan
    * @param user
    * @param peopleType
    * @param paymentAmount
    * @param referenceNumber
    * @param loanDetailsType
    * @param createdBy
    * @param createdOn
    * @param comments
    * @param folio
    */
   public LoanDetails(Loan loan, User user, PeopleType peopleType, BigDecimal paymentAmount, Integer referenceNumber, LoanDetailsType loanDetailsType, String createdBy, Date createdOn, String comments, String folio) {
      this.loan = loan;
      this.user = user;
      this.peopleType = peopleType;
      this.paymentAmount = paymentAmount;
      this.referenceNumber = referenceNumber;
      this.loanDetailsType = loanDetailsType;
      this.createdBy = createdBy;
      this.createdOn = createdOn;
      this.comments = comments;
      this.folio = folio;
   }

   /**
    *
    * @param loan
    * @param user
    * @param peopleType
    * @param paymentAmount
    * @param referenceNumber
    * @param loanDetailsType
    * @param createdBy
    * @param createdOn
    * @param comments
    * @param transferNumber
    * @param transferStatus
    */
   public LoanDetails(Loan loan, User user, PeopleType peopleType, BigDecimal paymentAmount, Integer referenceNumber, LoanDetailsType loanDetailsType, String createdBy, Date createdOn, String comments, String transferNumber, TransferStatus transferStatus) {
      this.loan = loan;
      this.user = user;
      this.peopleType = peopleType;
      this.paymentAmount = paymentAmount;
      this.referenceNumber = referenceNumber;
      this.loanDetailsType = loanDetailsType;
      this.createdBy = createdBy;
      this.createdOn = createdOn;
      this.comments = comments;
      this.transferNumber = transferNumber;
      this.transferStatus = transferStatus;
   }

   /**
    *
    * @param loan
    * @param user
    * @param peopleType
    * @param paymentAmount
    * @param referenceNumber
    * @param loanDetailsType
    * @param createdBy
    * @param createdOn
    * @param comments
    * @param transferNumber
    * @param transferStatus
    * @param folio
    */
   public LoanDetails(Loan loan, User user, PeopleType peopleType, BigDecimal paymentAmount, Integer referenceNumber, LoanDetailsType loanDetailsType, String createdBy, Date createdOn, String comments, String transferNumber, TransferStatus transferStatus, String folio) {
      this.loan = loan;
      this.user = user;
      this.peopleType = peopleType;
      this.paymentAmount = paymentAmount;
      this.referenceNumber = referenceNumber;
      this.loanDetailsType = loanDetailsType;
      this.createdBy = createdBy;
      this.createdOn = createdOn;
      this.comments = comments;
      this.transferNumber = transferNumber;
      this.transferStatus = transferStatus;
      this.folio = folio;
   }

   public String getId() {
      return id;
   }

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

   public Loan getLoan() {
      return loan;
   }

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

   public PeopleType getPeopleType() {
      return peopleType;
   }

   public void setPeopleType(PeopleType peopleType) {
      this.peopleType = peopleType;
   }

   public BigDecimal getPaymentAmount() {
      return paymentAmount;
   }

   public void setPaymentAmount(BigDecimal paymentAmount) {
      this.paymentAmount = paymentAmount;
   }

   public Integer getReferenceNumber() {
      return referenceNumber;
   }

   public void setReferenceNumber(Integer referenceNumber) {
      this.referenceNumber = referenceNumber;
   }

   public LoanDetailsType getLoanDetailsType() {
      return loanDetailsType;
   }

   public void setLoanDetailsType(LoanDetailsType loanDetailsType) {
      this.loanDetailsType = loanDetailsType;
   }

   public String getComments() {
      return comments;
   }

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

   public FeeStatus getFeeStatus() {
      return feeStatus;
   }

   public void setFeeStatus(FeeStatus feeStatus) {
      this.feeStatus = feeStatus;
   }

   public TransferStatus getTransferStatus() {
      return transferStatus;
   }

   public void setTransferStatus(TransferStatus transferStatus) {
      this.transferStatus = transferStatus;
   }

   public String getTransferNumber() {
      return transferNumber;
   }

   public void setTransferNumber(String transferNumber) {
      this.transferNumber = transferNumber;
   }

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

   public User getUser() {
      return user;
   }

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

   public BigDecimal getSaldoInsoluto() {
      return saldoInsoluto;
   }

   public void setSaldoInsoluto(BigDecimal saldoInsoluto) {
      this.saldoInsoluto = saldoInsoluto;
   }

   public Double getAbonoD() {
      return getPaymentAmount().doubleValue();
   }

   public String getFolio() {
      return folio;
   }

   public void setFolio(String folio) {
      this.folio = folio;
   }

   @Override
   public String toString() {
      return "LoanDetails{" + "referenceNumber=" + referenceNumber + ", comments=" + comments + ", createdBy=" + createdBy + '}';
   }

}
