package com.smokeyhotel.management.database;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

import com.awesome.db.AwesomeDatabase;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import com.smokeyhotel.management.reservation.Reservation;
import com.smokeyhotel.people.guest.Guest;
import com.smokeyhotel.room.Room;

/**
 * @author InsaneAboutTNT
 * This class houses the database
 * and provides methods for adding and
 * deleting data in the hotel database.
 */
public class Database {
	AwesomeDatabase awesomeDatabase;
	/**
	 * Initiate a data source and
	 * make a new AwesomeDatabase to use
	 */
	public Database() {
		try {
			FileReader reader = new FileReader("config.properties");
			Properties props = new Properties();
			props.load(reader);
			
			MysqlDataSource dataSource = new MysqlDataSource();
			dataSource.setUser(props.getProperty("user"));
			dataSource.setPassword(props.getProperty("password"));
			dataSource.setURL(props.getProperty("url"));
			awesomeDatabase = new AwesomeDatabase(dataSource);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * Add a reservation
	 * @param reservation
	 */
	public void insertReservation(Reservation reservation) {
		// TODO
		awesomeDatabase.createQuery("insert into app.reservation () values ()");
	}
	
	/**
	 * Returns awesomeDatabase
	 */
	public AwesomeDatabase getAwesomeDatabase() {
		return this.awesomeDatabase;
	}
	/**
	 * Add a guest
	 * @param guest
	 */
	public void insertGuest(Guest guest) {
		// TODO
		awesomeDatabase.createQuery("insert into app.guests () values ()");
	}
	/**
	 * Add a room
	 * @param room
	 */
	public void insertRoom(Room room) {
		// TODO
		awesomeDatabase.createQuery("insert into app.room () values ()");
	}
}

@@ -1379,32 +1379,41 @@
 on) %7B%0D%0A%09%09// TODO
+ do later
 %0D%0A%09%09awesomeDatab
@@ -1441,20 +1441,16 @@
 rt into 
-app.
 reservat
@@ -1466,24 +1466,168 @@
 lues ()%22);%0D%0A
+%09%09awesomeDatabase.createQuery(%22insert into guest_reservation values%22%0D%0A%09%09%09%09+ %22((select id from reservation where name=?,%22%0D%0A%09%09%09%09+ %22(select ))%22);%0D%0A
 %09%7D%0D%0A%09%0D%0A%09/**%0D
@@ -1742,24 +1742,120 @@
 abase;%0D%0A%09%7D%0D%0A
+%09/*%0D%0A%09 * Do not use yet (unless you want to ruin the database%0D%0A%09 * and your own life.)%0D%0A%09 * */%0D%0A
 %09/**%0D%0A%09 * Ad
@@ -1988,32 +1988,93 @@
 nto 
-app.
 guest
-s
  (
-) values ()%22
+name, dob, ...) values (?, ?)%22)%0D%0A%09%09    .params(guest.getName(), guest.getDob()
 );%0D%0A
@@ -2218,18 +2218,20 @@
 nto 
-app.
 room (
+number
 ) va
@@ -2232,25 +2232,51 @@
 er) values (
+?
 )%22)
+.params(room.getNumber())
 ;%0D%0A%09%7D%0D%0A%7D%0D%0A

Add unfinished scripts in Database.java