package me.jesensky.dan.playertracker;

import me.jesensky.dan.playertracker.exceptions.InvalidPacketException;
import me.jesensky.dan.playertracker.listeners.DataTransmissionListener;
import me.jesensky.dan.playertracker.net.Connection;
import me.jesensky.dan.playertracker.net.packets.LoginResponsePacket;
import me.jesensky.dan.playertracker.net.packets.Packet;
import me.jesensky.dan.playertracker.net.packets.PacketType;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Set;

public class DataManager extends Thread{
    private List<DataTransmissionListener> listeners;

    public DataManager(){
        super("Data Response Manager");
    }

    public int registerDataTransmissionListener(DataTransmissionListener listener){
        if(!this.listeners.contains(listener))
            this.listeners.add(listener);
        return this.listeners.indexOf(listener);
    }

    private String generateUUID(){
        //TODO generate
        return "";
    }

    private boolean attemptLogin(String user, String pass){
        //TODO verify credentials
        //Server.getSingleton().getDbManager();
        return false;
    }

    @Override
    public void run(){
        for(Connection c : Server.getSingleton().getConnectionManager().getConnections().values()){
            try {
                if (c instanceof ClientConnection) {
                    if (c.dataRemaining()) {
                        Packet p = c.readData();
                        Packet response = null;

                        switch(p.getType()){
                            case LOGIN:

                                response = new LoginResponsePacket((byte)3);
                                break;
                            default:
                                continue;
                        }
                        response.sendData(c);
                    }
                }
            }catch(IOException | InvalidPacketException e){
                //TODO log exception
            }
        }
    }
}
@@ -276,92 +276,16 @@
 net.
-packets.LoginResponsePacket;%0Aimport me.jesensky.dan.playertracker.net.packets.Packet
+NetUtils
 ;%0Aim
@@ -335,18 +335,9 @@
 ets.
-PacketType
+*
 ;%0A%0Ai
@@ -1023,18 +1023,16 @@
         
-//
 Server.g
@@ -1249,61 +1249,8 @@
 y %7B%0A
-                if (c instanceof ClientConnection) %7B%0A
     
@@ -1473,17 +1473,16 @@
  LOGIN:%0A
-%0A
         
@@ -1589,16 +1589,357 @@
  break;%0A
+                            case FETCH_DATA:%0A                                FetchPacket packet = (FetchPacket)p;%0A                                String name, notes, violations;%0A                                UserViolationLevel vl;%0A                                response = new DataResponsePacket();%0A                                break;%0A
         
@@ -2081,16 +2081,16 @@
 ata(c);%0A
+
         
@@ -2103,34 +2103,16 @@
       %7D%0A
-                %7D%0A
         

Complete Connection refactor; add a stub to fetch data resposne