//    Space MMO    
//  Author: Josh Hughes   


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Game.ECS.Buildings;
using Unity.Collections;

[BurstCompile]
[UpdateInGroup(typeof(InitializationSystemGroup))]
public partial struct StartingPointSpawningSystem : ISystem
{
	[BurstCompile]
	public void OnCreate(ref SystemState state)
	{

	}

	[BurstCompile]
	public void OnDestroy(ref SystemState state)
	{

	}

	[BurstCompile]
	public void OnUpdate(ref SystemState state)
	{
		// Eventually wewill want this updating every frame as we will want to spawn new players during the simulation
		state.Enabled = false;
		EntityCommandBuffer.ParallelWriter ecb = SystemAPI.GetSingleton<EndInitializationEntityCommandBufferSystem.Singleton>()
													.CreateCommandBuffer(state.WorldUnmanaged).AsParallelWriter();

		state.Dependency = new StartingPointSpawnerJob()
		{
			ecb = ecb
		}.ScheduleParallel(state.Dependency);
	}

	public partial struct StartingPointSpawnerJob : IJobEntity
	{
		public EntityCommandBuffer.ParallelWriter ecb;

		private void Execute([ChunkIndexInQuery] int chunkIndex, in StartingPointProperties startingPointProperties)
		{
			Entity ship = ecb.Instantiate(chunkIndex, startingPointProperties.playerBaseEntity);
		}
	}
}