package de.afbb.bibo.servletclient.connection;

import java.net.ConnectException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import de.afbb.bibo.share.IMediumService;
import de.afbb.bibo.share.beans.BeanExclusionStrategy;
import de.afbb.bibo.share.callback.EventListener;
import de.afbb.bibo.share.model.Borrower;
import de.afbb.bibo.share.model.Medium;

public class MediumServiceImpl implements IMediumService {

	private static final Gson gson = new GsonBuilder().addSerializationExclusionStrategy(new BeanExclusionStrategy())
			.create();

	private final Set<EventListener> listeners = new HashSet<EventListener>();

	@Override
	public void update(final Medium medium) throws ConnectException {
		// TODO Auto-generated method stub

	}

	@Override
	public void create(final Medium medium) throws ConnectException {
		// TODO Auto-generated method stub

	}

	@Override
	public Medium getMedium(final int id) throws ConnectException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Medium getMedium(final String isbn) throws ConnectException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Collection<Borrower> listLent(final String isbn) throws ConnectException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Collection<Medium> list() throws ConnectException {
		final HttpResponse resp = ServerConnection.getInstance().request("/stock/listMedia", "GET", null, null);
		if (resp.getStatus() == HttpServletResponse.SC_OK) {
			final Collection<Medium> result = new HashSet<>();
			final String[] data = resp.getData().split("\n");
			for (int i = 0; i < data.length; i++) {
				final Medium medium = gson.fromJson(data[i], Medium.class);
				if (medium != null) {
					result.add(medium);
				}
			}
			return result;
		} else {
			throw new ConnectException("Wrong status code. Recieved was: " + resp.getStatus());
		}
	}

	@Override
	public void delete(final Medium medium) throws ConnectException {
		// TODO Auto-generated method stub

	}

	@Override
	public void register(final EventListener listener) {
		listeners.add(listener);
	}

}

@@ -871,33 +871,122 @@
 ted method stub%0A
+%09%09// currently never called%0A%09%09throw new UnsupportedOperationException(%22not implemented%22);
 %0A
-
 %09%7D%0A%0A%09@Override%0A%09
@@ -1080,33 +1080,122 @@
 ted method stub%0A
+%09%09// currently never called%0A%09%09throw new UnsupportedOperationException(%22not implemented%22);
 %0A
-
 %09%7D%0A%0A%09@Override%0A%09
@@ -1293,35 +1293,110 @@
 thod stub%0A%09%09
-return null
+// currently never called%0A%09%09throw new UnsupportedOperationException(%22not implemented%22)
 ;%0A%09%7D%0A%0A%09@Over
@@ -1505,35 +1505,110 @@
 thod stub%0A%09%09
-return null
+// currently never called%0A%09%09throw new UnsupportedOperationException(%22not implemented%22)
 ;%0A%09%7D%0A%0A%09@Over
@@ -1738,19 +1738,94 @@
 b%0A%09%09
-return null
+// currently never called%0A%09%09throw new UnsupportedOperationException(%22not implemented%22)
 ;%0A%09%7D
@@ -2546,40 +2546,92 @@
 %09// 
-TODO Auto-generated method stub%0A
+currently never called%0A%09%09throw new UnsupportedOperationException(%22not implemented%22);
 %0A%09%7D%0A

throw exceptions in not implemented methods