package space.animefu.starfallhaven;

import org.junit.Test;
import java.util.EnumSet;
import static org.junit.Assert.*;
import static space.animefu.starfallhaven.ColonySystems.*;

public final class V2ExpandedPersistenceTest {
 @Test public void allExpandedColonySystemsRoundTrip()throws Exception{
  GameWorld w=new GameWorld(220);w.wood=100;w.stone=100;w.crystal=100;w.components=3;w.nextEntityId=80;
  GameWorld.Colonist c=w.colonists.get(0);c.drafted=true;c.order=OrderType.MOVE;c.tx=25;c.ty=16;c.mood=43;c.comfort=67;c.safety=38;c.setPriority(WorkType.CRAFT,1);c.addInjury("Prism cut",12,1.5f);c.thoughts.add(new Thought("Shared supper",6,20));
  Blueprint bed=w.placeBlueprint(StructureType.BED,18,12);bed.workDone=2.5f;
  Blueprint door=w.placeBlueprint(StructureType.DOOR,19,12);door.complete=true;
  Blueprint fab=w.placeBlueprint(StructureType.FABRICATOR,22,12);fab.complete=true;
  StockpileZone z=w.addStockpile(17,15,2,2,EnumSet.of(ResourceType.WOOD,ResourceType.FOOD));
  ResourcePile p=w.addResourcePile(ResourceType.WOOD,9,17.5f,15.5f);p.stored=true;p.reservedBy=c.id;
  ProductionJob j=w.queueProduction(fab.id,Recipe.NUTRIENT_PACK,3);j.workDone=1.25f;
  byte[] encoded=GameWorldSave.encode(w);GameWorld r=GameWorldSave.decode(encoded);
  assertEquals(4,GameWorldSave.VERSION);assertEquals(3,r.components);assertEquals(w.nextEntityId,r.nextEntityId);
  GameWorld.Colonist rc=r.colonists.get(0);assertEquals(c.id,rc.id);assertTrue(rc.drafted);assertEquals(OrderType.MOVE,rc.order);assertEquals(43,rc.mood,0);assertEquals(1,rc.priority(WorkType.CRAFT));assertEquals(1,rc.injuries.size());assertEquals(1,rc.thoughts.size());
  assertEquals(3,r.blueprints.size());assertEquals(1,r.stockpiles.size());assertTrue(r.stockpiles.get(0).accepts(ResourceType.FOOD));assertFalse(r.stockpiles.get(0).accepts(ResourceType.STONE));
  assertEquals(1,r.resourcePiles.size());assertEquals(c.id,r.resourcePiles.get(0).reservedBy);assertEquals(1,r.productionJobs.size());assertEquals(3,r.productionJobs.get(0).remaining);assertEquals(1.25f,r.productionJobs.get(0).workDone,0);
  assertArrayEquals(encoded,GameWorldSave.encode(r));
 }
}
