package electrosphere.entity;

import static org.junit.jupiter.api.Assertions.*;

import org.joml.Vector3d;
import org.junit.jupiter.api.Disabled;

import electrosphere.engine.Globals;
import electrosphere.entity.types.common.CommonEntityUtils;
import electrosphere.entity.types.creature.CreatureTemplate;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.foliage.FoliageUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.data.common.CommonEntityMap;
import electrosphere.game.data.common.CommonEntityType;
import electrosphere.game.data.creature.type.CreatureData;
import electrosphere.game.data.creature.type.CreatureTypeLoader;
import electrosphere.game.data.foliage.type.FoliageType;
import electrosphere.game.data.foliage.type.FoliageTypeLoader;
import electrosphere.game.data.item.Item;
import electrosphere.game.data.item.ItemDataMap;
import electrosphere.test.annotations.IntegrationTest;
import electrosphere.test.template.EntityTestTemplate;
import electrosphere.test.testutils.TestEngineUtils;

/**
 * Tests for spawning entities
 */
public class SpawnAllEntitiesTests extends EntityTestTemplate {
    
    @Disabled
    @IntegrationTest
    public void spawnAllEntities(){
        Globals.ENGINE_DEBUG = false;
        assertDoesNotThrow(() -> {

            CreatureTypeLoader creatureLoader = Globals.gameConfigCurrent.getCreatureTypeLoader();
            for(CreatureData creature : creatureLoader.getTypes()){
                CreatureUtils.serverSpawnBasicCreature(Globals.realmManager.first(), new Vector3d(0.1,0.1,0.1), creature.getId(), CreatureTemplate.createDefault(creature.getId()));
            }

            ItemDataMap itemMap = Globals.gameConfigCurrent.getItemMap();
            for(Item item : itemMap.getTypes()){
                ItemUtils.serverSpawnBasicItem(Globals.realmManager.first(), new Vector3d(0.1,0.1,0.1), item.getId());
            }

            FoliageTypeLoader foliageTypeMap = Globals.gameConfigCurrent.getFoliageMap();
            for(FoliageType foliage : foliageTypeMap.getTypes()){
                FoliageUtils.serverSpawnTreeFoliage(Globals.realmManager.first(), new Vector3d(0.1,0.1,0.1), foliage.getId(), 0);
            }

            CommonEntityMap commonEntityMap = Globals.gameConfigCurrent.getObjectTypeMap();
            for(CommonEntityType entity : commonEntityMap.getTypes()){
                CommonEntityUtils.serverSpawnBasicObject(Globals.realmManager.first(), new Vector3d(0.1,0.1,0.1), entity.getId());
            }

            //wait for entities to propagate across network
            TestEngineUtils.simulateFrames(100);
        });
    }

}
