/*
 * 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.taxiservicios.model.mutual;

import com.arrebol.taxiservicios.model.catalog.Location;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.BasicType;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Oscar Vargas
 */
public class MutualClosingDay implements Serializable {

    private String id;
    private User user;
    private BigDecimal amountPaid;
    private BigDecimal amountExpected;
    private BasicType activeStatus;
    private String comments;
    private User createdBy;
    private Date createdOn;
    private User lastUpdatedBy;
    private Date lastUpdatedOn;
    private Location location;
    private Set closingDayDetails = new HashSet(0);

    public MutualClosingDay() {
    }

    /**
     *
     * @param id
     */
    public MutualClosingDay(String id) {
        this.id = id;
    }

    /**
     *
     * @param id
     * @param user
     * @param amountPaid
     * @param amountExpected
     * @param comments
     * @param createdOn
     */
    public MutualClosingDay(String id, User user, BigDecimal amountPaid, BigDecimal amountExpected, String comments, Date createdOn) {
        this.id = id;
        this.user = user;
        this.amountPaid = amountPaid;
        this.amountExpected = amountExpected;
        this.comments = comments;
        this.createdOn = createdOn;
    }

    /**
     *
     * @param id
     * @param user
     * @param amountPaid
     * @param amountExpected
     * @param comments
     * @param createdOn
     * @param createdBy
     */
    public MutualClosingDay(String id, User user, BigDecimal amountPaid, BigDecimal amountExpected, String comments, Date createdOn, User createdBy) {
        this.id = id;
        this.user = user;
        this.amountPaid = amountPaid;
        this.amountExpected = amountExpected;
        this.comments = comments;
        this.createdOn = createdOn;
        this.createdBy = createdBy;
    }
    
    public MutualClosingDay(String id, User user, BigDecimal amountPaid, BigDecimal amountExpected, String comments, Date createdOn, User createdBy, Location location) {
        this.id = id;
        this.user = user;
        this.amountPaid = amountPaid;
        this.amountExpected = amountExpected;
        this.comments = comments;
        this.createdOn = createdOn;
        this.createdBy = createdBy;
        this.location = location;
    }

    /**
     *
     * @param id
     * @param amountPaid
     * @param amountExpected
     * @param comments
     * @param createdOn
     */
    public MutualClosingDay(String id, BigDecimal amountPaid, BigDecimal amountExpected, String comments, Date createdOn) {
        this.id = id;
        this.amountPaid = amountPaid;
        this.amountExpected = amountExpected;
        this.comments = comments;
        this.createdOn = createdOn;
    }

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    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 BigDecimal getAmountPaid() {
        return amountPaid;
    }

    public void setAmountPaid(BigDecimal amountPaid) {
        this.amountPaid = amountPaid;
    }

    public BigDecimal getAmountExpected() {
        return amountExpected;
    }

    public void setAmountExpected(BigDecimal amountExpected) {
        this.amountExpected = amountExpected;
    }

    public BasicType getActiveStatus() {
        return activeStatus;
    }

    public void setActiveStatus(BasicType activeStatus) {
        this.activeStatus = activeStatus;
    }

    public String getComments() {
        return comments;
    }

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

    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 Set getClosingDayDetails() {
        return closingDayDetails;
    }

    public void setClosingDayDetails(Set closingDayDetails) {
        this.closingDayDetails = closingDayDetails;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + Objects.hashCode(this.id);
        return hash;
    }

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

    @Override
    public String toString() {
        return "ClosingDay{" + "user=" + user + ", activeStatus=" + activeStatus + ", comments=" + comments + ", createdOn=" + createdOn + '}';
    }
    
    public boolean getAction(Date lastStableSmallBox) {
        Date date = createdOn;
        boolean action = true;
        try {
            SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");

            String dateStr = dt1.format(date);
            date = dt1.parse(dateStr);

            action = date.after(lastStableSmallBox);

        } catch (ParseException ex) {
            Logger.getLogger(MutualClosingDay.class.getName()).log(Level.SEVERE, null, ex);
        }
        return action;
    }

    private static final long serialVersionUID = -2237441298143436285L;

}
