package skadistats.clarity.parser;

import java.util.HashSet;
import java.util.Set;

import com.dota2.proto.Demo;
import com.dota2.proto.DotaUsermessages;
import com.dota2.proto.Netmessages;
import com.dota2.proto.Networkbasetypes;

public class Profile {

    public static Profile NET_TICK = new Profile()
        .append(
            Netmessages.CNETMsg_Tick.class
        );

    public static Profile REPLAY_TIME = new Profile()
        .append(
            Netmessages.CSVCMsg_ServerInfo.class
        );
    
    public static Profile STRING_TABLES = new Profile()
        .append(
            Netmessages.CSVCMsg_CreateStringTable.class,
            Netmessages.CSVCMsg_UpdateStringTable.class
        );

    public static Profile SEND_TABLES = new Profile()
        .append(
            Demo.CDemoClassInfo.class,
            Demo.CDemoSyncTick.class,
            Netmessages.CSVCMsg_SendTable.class
        );
    
    public static Profile VOICE_DATA = new Profile()
        .append(
            Netmessages.CSVCMsg_VoiceInit.class,
            Netmessages.CSVCMsg_VoiceData.class
        );

    public static Profile BASELINES = new Profile()
        .dependsOn(STRING_TABLES);

    public static Profile TRANSIENT_DATA = new Profile()
        .dependsOn(NET_TICK);
    
    public static Profile USERMESSAGE_CONTAINER = new Profile()
        .append(
            Networkbasetypes.CSVCMsg_UserMessage.class
        );

    public static Profile ENTITIES = new Profile()
        .dependsOn(SEND_TABLES)
        .dependsOn(BASELINES)
        .append(
            Netmessages.CSVCMsg_PacketEntities.class
        );

    public static Profile TEMP_ENTITIES = new Profile()
        .dependsOn(TRANSIENT_DATA)
        .dependsOn(SEND_TABLES)
        .append(
            Netmessages.CSVCMsg_TempEntities.class
        );

    public static Profile MODIFIERS = new Profile()
        .dependsOn(ENTITIES)
        .dependsOn(STRING_TABLES);
    
    public static Profile GAME_EVENTS = new Profile()
        .append(
            Netmessages.CSVCMsg_GameEventList.class,
            Networkbasetypes.CSVCMsg_GameEvent.class
        );
    
    public static Profile PROJECTILES = new Profile()
        .dependsOn(ENTITIES)
        .dependsOn(USERMESSAGE_CONTAINER)
        .append(
            DotaUsermessages.CDOTAUserMsg_CreateLinearProjectile.class,
            DotaUsermessages.CDOTAUserMsg_DestroyLinearProjectile.class,
            DotaUsermessages.CDOTAUserMsg_DodgeTrackingProjectiles.class
        );
    
    public static Profile CHAT_MESSAGES = new Profile()
    .dependsOn(TRANSIENT_DATA)
    .dependsOn(USERMESSAGE_CONTAINER)
    .append(
        DotaUsermessages.CDOTAUserMsg_ChatEvent.class
    );
    
    public static Profile ALL = new Profile() {
        @Override
        public boolean contains(Class<?> clazz) {
            return true;
        }
    };
    
    private final Set<Class<?>> protoClasses = new HashSet<Class<?>>();

    public Profile append(Class<?>... classes) {
        for (Class<?> clazz : classes) {
            protoClasses.add(clazz);
        }
        return this;
    }

    public Profile dependsOn(Profile other) {
        for (Class<?> clazz : other.protoClasses) {
            protoClasses.add(clazz);
        }
        return this;
    }

    public boolean contains(Class<?> clazz) {
        return protoClasses.contains(clazz);
    }

}

@@ -332,36 +332,32 @@
 ppend(%0D%0A        
-    
 Netmessages.CNET
@@ -364,32 +364,32 @@
 Msg_Tick.class%0D%0A
+
         );%0D%0A%0D%0A  
@@ -451,36 +451,32 @@
       .append(%0D%0A
-    
         Netmessa
@@ -497,32 +497,32 @@
 rverInfo.class%0D%0A
+
         );%0D%0A    
@@ -509,38 +509,34 @@
 ss%0D%0A        );%0D%0A
-    
 %0D%0A
+
     public stati
@@ -928,38 +928,34 @@
 ss%0D%0A        );%0D%0A
-    
 %0D%0A
+
     public stati
@@ -1299,30 +1299,26 @@
 NET_TICK);%0D%0A
-    
 %0D%0A
+
     public s
@@ -1380,36 +1380,32 @@
       .append(%0D%0A
-    
         Networkb
@@ -1432,32 +1432,32 @@
 rMessage.class%0D%0A
+
         );%0D%0A%0D%0A  
@@ -1981,30 +1981,26 @@
 G_TABLES);%0D%0A
-    
 %0D%0A
+
     public s
@@ -2034,32 +2034,68 @@
  new Profile()%0D%0A
+        .dependsOn(TRANSIENT_DATA)%0D%0A
         .append(
@@ -2208,38 +2208,34 @@
 ss%0D%0A        );%0D%0A
-    
 %0D%0A
+
     public stati
@@ -2589,38 +2589,34 @@
 ss%0D%0A        );%0D%0A
-    
 %0D%0A
+
     public stati
@@ -2652,24 +2652,28 @@
  Profile()%0D%0A
+    
     .depends
@@ -2692,24 +2692,28 @@
 _DATA)%0D%0A    
+  
+  
 .dependsOn(U
@@ -2731,24 +2731,28 @@
 CONTAINER)%0D%0A
+    
     .append(
@@ -2753,32 +2753,36 @@
 ppend(%0D%0A        
+    
 DotaUsermessages
@@ -2816,24 +2816,24 @@
 ss%0D%0A    
-);%0D%0A
     
+);%0D%0A
 %0D%0A    pu
@@ -2990,20 +2990,16 @@
     %7D;%0D%0A
-    
 %0D%0A    pr

fix GAME_EVENTS not being transient (thanks raz)