package net;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import user_manag.Login;
import GetAction.GetEvent;
import GetAction.GetVideo;
import PostAction.AddAudio;
import PostAction.AddEvent;
import PostAction.AddVideo;
import android.util.Log;
import basicClass.Event;
import basicClass.Location;
import basicClass.User;

public class HttpActionManager {
	public static final String TAG = "HttpActionManager";
	
	
	public List<Event> searchEventByKeyWord(String key_word){
		List<Event> event = null;
		GetEvent se = new GetEvent();
		try {
			event = se.getEventByKeyword(key_word);
		} catch (Exception e) {
			Log.e(TAG, "error: " + e.toString());
		}
		return event;
	}
	
	public List<Event> searchEventByLocationGPS(int up, int down, int right, int left) {
		List<Event> event = null;
		GetEvent se = new GetEvent();
		try {
			event = se.getEventByLocationGPS(up, down, right, left);
		} catch (Exception e) {
			Log.e(TAG, "error: " + e.toString());
		}
		return event;
	}
	
	public void addEvent(String name, User user, Location location, 
			String stime, String etime, String descript) {
		Event newEvent = new Event();
			
		newEvent.setName(name);
		newEvent.setUser(user);
		newEvent.setLocation(location);
		newEvent.setStartTime(stime);
		newEvent.setStopTime(etime);
		newEvent.setDescript(descript);
		
		AddEvent ae = new AddEvent();
		try {
			ae.addEvent(newEvent);
		} catch (Exception e) {
			Log.e(TAG, "error: " + e.toString());
			e.printStackTrace();
		}
		
		
	}
	
	public List<String> getVideo(int eid) throws Exception {
		GetVideo gv = new GetVideo();
		List<String> paths = new ArrayList<String>();
		paths = gv.getVideoByEid(eid);
		return paths;
	}
	
	public void addVideo(int eid, String path) {
		AddVideo av = new AddVideo();
		try {
			av.addVideoToEvent(path, eid);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void addAudio(int eid, String path) {
		AddAudio aa = new AddAudio();
		try {
			aa.addAudioToEvent(path, eid);
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public boolean login(String name, String pw) throws IOException {
		boolean result = false;
		Login l = new Login();
		result = l.login(name, pw);
		return result;
	}

}
