import java.util.Date;
import java.text.SimpleDateFormat;

/**
 * class Booking
 * Represents a booking by a user for a tour
 * 
 * @author Jim
 * @version 1.0
 */
public class Booking
{
    private int bookingID;
    private User user;
    private Tour tour;
    private int adults;
    private int children;
    private String bookingDate;
    private String status;


    /**
     * Constructor for Booking
     *
     */
    public Booking() 
    {
        this.bookingID = 0;    
    }
    
    
    /**
     * Constructor for new Booking objects
     *
     * @param user the user for this booking
     * @param tour the tour for this booking
     * @param adults the number of adults
     * @param children the number of children
     * @param bookingDate the booking date
     *
     */
    public Booking( User user, Tour tour, int adults, int children) 
    {
        this.bookingID = 0;     // value will be set by database when booking is stored, don't set here
        this.user = user;
        this.tour = tour;
        this.adults = adults;
        this.children = children;
        
        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy" );    
        Date now = new Date();
        this.bookingDate = formatter.format(now);  // create string with today's date. Should really use proper date types in Java and database
        this.status = "tickets not sent";
        updatePackageSales();
    }
    
    /**
     * Updates sales of related Package 
     * Adds number of adults and number of children in this booking to package total
     * 
     */
    public void updatePackageSales() {
        Package p =this.tour.getHolidayPackage();
        int currentSales = p.getSales();
        p.setSales(currentSales + this.adults + this.children);
    }
    
    /**
     * Getter for bookingID
     *
     *@return value of bookingID
     */
    public int getBookingID() {
        return bookingID;
    }

    /**
     * Setter for bookingID
     *
     *@param bookingID new value of bookingID
     */
    public void setBookingID(int bookingID) {
        this.bookingID = bookingID;
    }
    
    /**
     * Getter for tour
     *
     *@return related Tour object
     */
    public Tour getTour() {
        return tour;
    }

    /**
     * Setter for tour
     *
     *@param tour a Tour object
     */
    public void setTour(Tour tour) {
        this.tour = tour;
    }
    
    /**
     * Getter for user
     *
     *@return related User object
     */
    public User getUser() {
        return user;
    }

    /**
     * Setter for user
     *
     *@param user a User object
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * Getter for adults
     *
     *@return value of adults
     */
    public int getAdults() {
        return adults;
    }

    /**
     * Setter for adults
     *
     *@param adults new adults value
     */
    public void setAdults(int adults) {
        this.adults = adults;
    }

    /**
     * Getter for children
     *
     *@return value of children
     */
    public int getChildren() {
        return children;
    }

    /**
     * Setter for children
     *
     *@param children new children value
     */
    public void setChildren(int children) {
        this.children = children;
    }

    /**
     * Getter for bookingDate
     *
     *@return value of bookingDate
     */
    public String getBookingDate() {
        return bookingDate;
    }

    /**
     * Setter for bookingDate
     *
     *@param bookingDate new bookingDate value
     */
    public void setBookingDate(String bookingDate) {
        this.bookingDate = bookingDate;
    }

    /**
     * Getter for status
     *
     *@return value of status
     */
    public String getStatus() {
        return status;
    }

    /**
     * Setter for status
     *
     *@param status new status value
     */
    public void setStatus(String status) {
        this.status = status;
    }
    
}
