/*
 * Gets the max occupancy for a given day.
 */
func GetMaxOccupancy(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()

	var auth S.AuthToken
	var date string

	for k, v := range r.Form {
		if k == "user" {
			auth.User = strings.Join(v, "")
		} else if k == "date" {
			date = strings.Join(v, "")
		} else if k == "code" {
			auth.Code = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) {
		fmt.Fprintf(w, "Please login")
		return
	}

	if db.HasHotel(auth) {
		fmt.Fprintf(w, db.GetMaxOccupancy(auth, date))
	} else {
		fmt.Fprintf(w, "You do not work for a hotel")
	}
}
/*
 * Gets the max occupancy for a given day.
 */
func GetMaxOccupancy(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")

	r.ParseForm()

	var auth S.AuthToken
	var date string

	hotel := "none"

	for k, v := range r.Form {
       	if k == "user" {
			auth.User = strings.Join(v, "")
		} else if k == "date" {
			date = strings.Join(v, "")
		} else if k == "code" {
			auth.Code = strings.Join(v, "")
		} else if k == "hotel" {
			hotel = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) || hotel == "none" {
		fmt.Fprintf(w, "{\"Please login\"}")
		return
	}


	occupancyString := strconv.Itoa(db.GetMaxOccupancy(date, hotel))
	
	//fmt.Fprintf(w, "10")
	fmt.Fprintf(w, occupancyString)

	// real one here 
	//fmt.Fprintf(w, occupancyString)

	// if db.HasHotel(auth) {
	// 	fmt.Fprintf(w, db.GetMaxOccupancy(auth, date))
	// } else {
	// 	fmt.Fprintf(w, "You do not work for a hotel")
	// }
}