/*
 * Copyright 2015 Florian Hassanen
 *
 * This file is part of mmo-server.
 *
 * mmo-server is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * mmo-server is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with mmo-server.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

package mmo.server;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import dagger.Module;
import dagger.Provides;
import io.netty.util.HashedWheelTimer;

import javax.inject.Singleton;

@Module(injects = Server.class)
public class ServerModule {

    @Provides
    @Singleton
    HashedWheelTimer provideHashedWheelTimer() {
        return new HashedWheelTimer();
    }

    @Provides
    @Singleton
    ObjectMapper provideObjectMapper() {
        return new ObjectMapper()
                .setDefaultTyping(
                        new ObjectMapper.DefaultTypeResolverBuilder(
                                ObjectMapper.DefaultTyping
                                        .OBJECT_AND_NON_CONCRETE)
                                .init(
                                        JsonTypeInfo.Id.MINIMAL_CLASS,
                                        null)
                                .inclusion(JsonTypeInfo.As.PROPERTY)
                                .typeProperty("type")
                )
                .setSerializationInclusion(JsonInclude.Include.NON_NULL)
                .enable(SerializationFeature.INDENT_OUTPUT)
                .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    }
}

@@ -870,16 +870,64 @@
 peInfo;%0A
+import com.fasterxml.jackson.databind.JavaType;%0A
 import c
@@ -970,16 +970,16 @@
 Mapper;%0A
-
 import c
@@ -1114,16 +1114,51 @@
 elTimer;
+%0Aimport mmo.server.message.Message;
 %0A%0Aimport
@@ -1634,16 +1634,36 @@
 ltTyping
+.JAVA_LANG_OBJECT) %7B
 %0A       
@@ -1671,32 +1671,46 @@
                 
+    @Override%0A
                 
@@ -1713,33 +1713,501 @@
     
-.OBJECT_AND_NON_CONCRETE)
+            public boolean useForType(JavaType t) %7B%0A                                Class%3C?%3E clazz = t.getRawClass();%0A                                if (clazz == null) %7B%0A                                    return super.useForType(t);%0A                                %7D else %7B%0A                                    return Message.class%0A                                            .isAssignableFrom(clazz);%0A                                %7D%0A%0A                            %7D%0A                        %7D
 %0A   

use default typing more strictly: only for messages and objects