#pragma once

#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"

#include "component_action_spawn.h"
#include "../stat/component_game_entity_type.h"

#define COMPONENT_ACTION_WAVE_SPAWN_TIMER_BASE 3600
#define COMPONENT_ACITON_WAVE_SPAWN_TIMER_LEVEL_MULTIPLIER 300
#define COMPONENT_ACTION_WAVE_SPAWN_TIMER_MIN 1800

#define COMPONENT_ACTION_WAVE_COUNT 30

static const GameEntityType WAVE_ONE_ENEMIES[1] 		= { GAME_ENTITY_CUPPER };
static const GameEntityType WAVE_TWO_ENEMIES[1] 		= { GAME_ENTITY_CHIPPER };
static const GameEntityType WAVE_THREE_ENEMIES[1] 		= { GAME_ENTITY_CRUMBLER};
static const GameEntityType WAVE_FOUR_ENEMIES[2] 		= { GAME_ENTITY_CUPPER, GAME_ENTITY_CHIPPER };
static const GameEntityType WAVE_FIVE_ENEMIES[2] 		= { GAME_ENTITY_CUPPER, GAME_ENTITY_CRUMBLER };
static const GameEntityType WAVE_SIX_ENEMIES[2] 		= { GAME_ENTITY_CHIPPER, GAME_ENTITY_CRUMBLER };
static const GameEntityType WAVE_SEVEN_ENEMIES[3] 		= { GAME_ENTITY_CUPPER, GAME_ENTITY_CHIPPER, GAME_ENTITY_CRUMBLER };
static const GameEntityType WAVE_EIGHT_ENEMIES[3] 		= { GAME_ENTITY_CUPPER, GAME_ENTITY_CHIPPER, GAME_ENTITY_CRUMBLER };
static const GameEntityType WAVE_NINE_ENEMIES[1] 		= { GAME_ENTITY_CHIP };
static const GameEntityType WAVE_TEN_ENEMIES[4] 		= { GAME_ENTITY_CUPPER, GAME_ENTITY_CHIPPER, GAME_ENTITY_CRUMBLER, GAME_ENTITY_CHIP };
static const GameEntityType WAVE_ELEVEN_ENEMIES[1] 		= { GAME_ENTITY_CUSTARPEDO };
static const GameEntityType WAVE_TWELVE_ENEMIES[2] 		= { GAME_ENTITY_CUPPER, GAME_ENTITY_CUSTARPEDO };
static const GameEntityType WAVE_THIRTEEN_ENEMIES[2] 		= { GAME_ENTITY_CUPPER, GAME_ENTITY_CUSTARPEDO };
static const GameEntityType WAVE_FOURTEEN_ENEMIES[2] 		= { GAME_ENTITY_CRUMBLER, GAME_ENTITY_CUSTARPEDO };
static const GameEntityType WAVE_FIFTEEN_ENEMIES[2] 		= { GAME_ENTITY_CHIP, GAME_ENTITY_CUSTARPEDO };
static const GameEntityType WAVE_SIXTEEN_ENEMIES[1] 		= { GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_SEVENTEEN_ENEMIES[2] 		= { GAME_ENTITY_CUPPER, GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_EIGHTEEN_ENEMIES[2] 		= { GAME_ENTITY_CHIPPER, GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_NINETEEN_ENEMIES[2] 		= { GAME_ENTITY_CRUMBLER, GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_TWENTY_ENEMIES[2] 		= { GAME_ENTITY_CHIP, GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_TWENTY_ONE_ENEMIES[2]  	= { GAME_ENTITY_CUSTARPEDO, GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_TWENTY_TWO_ENEMIES[3]  	= { GAME_ENTITY_CUPPER, GAME_ENTITY_CUSTARPEDO, GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_TWENTY_THREE_ENEMIES[4] 	= { GAME_ENTITY_CUPPER, GAME_ENTITY_CHIPPER, GAME_ENTITY_CUSTARPEDO, GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_TWENTY_FOUR_ENEMIES[4]	 	= { GAME_ENTITY_CUPPER, GAME_ENTITY_CRUMBLER, GAME_ENTITY_CUSTARPEDO, GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_TWENTY_FIVE_ENEMIES[3] 	= { GAME_ENTITY_CUPPER, GAME_ENTITY_CHIPPER, GAME_ENTITY_CRUMBLER };
static const GameEntityType WAVE_TWENTY_SIX_ENEMIES[1] 		= { GAME_ENTITY_CUSTARPEDO };
static const GameEntityType WAVE_TWENTY_SEVEN_ENEMIES[1] 	= { GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_TWENTY_EIGHT_ENEMIES[5] 	= { GAME_ENTITY_CUPPER, GAME_ENTITY_CHIPPER, GAME_ENTITY_CRUMBLER, GAME_ENTITY_CUSTARPEDO, GAME_ENTITY_EXCORSANT };
static const GameEntityType WAVE_TWENTY_NINE_ENEMIES[1] 	= { GAME_ENTITY_CHIP };
static const GameEntityType WAVE_THIRTY_ENEMIES[6] 		= { GAME_ENTITY_CUPPER, GAME_ENTITY_CHIPPER, GAME_ENTITY_CRUMBLER, GAME_ENTITY_CHIP, GAME_ENTITY_CUSTARPEDO, GAME_ENTITY_EXCORSANT };

static const SpawnWave SPAWN_WAVES[COMPONENT_ACTION_WAVE_COUNT] =
{
	{ .types = (GameEntityType*)WAVE_ONE_ENEMIES, 		.typeCount = 1, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TWO_ENEMIES, 		.typeCount = 1, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_THREE_ENEMIES, 	.typeCount = 1, .timer = 3600},
	{ .types = (GameEntityType*)WAVE_FOUR_ENEMIES, 		.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_FIVE_ENEMIES, 		.typeCount = 2, .timer = 3600},
	{ .types = (GameEntityType*)WAVE_SIX_ENEMIES, 		.typeCount = 2, .timer = 3600},
	{ .types = (GameEntityType*)WAVE_SEVEN_ENEMIES, 	.typeCount = 3, .timer = 3600},
	{ .types = (GameEntityType*)WAVE_EIGHT_ENEMIES, 	.typeCount = 3, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_NINE_ENEMIES, 		.typeCount = 1, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TEN_ENEMIES, 		.typeCount = 4, .timer = 3600},
	{ .types = (GameEntityType*)WAVE_ELEVEN_ENEMIES, 	.typeCount = 1, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TWELVE_ENEMIES, 	.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_THIRTEEN_ENEMIES, 	.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_FOURTEEN_ENEMIES, 	.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_FIFTEEN_ENEMIES, 	.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_SIXTEEN_ENEMIES, 	.typeCount = 1, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_SEVENTEEN_ENEMIES, 	.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_EIGHTEEN_ENEMIES, 	.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_NINETEEN_ENEMIES, 	.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TWENTY_ENEMIES, 	.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TWENTY_ONE_ENEMIES, 	.typeCount = 2, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TWENTY_TWO_ENEMIES, 	.typeCount = 3, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TWENTY_THREE_ENEMIES, 	.typeCount = 4, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TWENTY_FOUR_ENEMIES, 	.typeCount = 4, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TWENTY_FIVE_ENEMIES,	.typeCount = 3, .timer = 1800},
	{ .types = (GameEntityType*)WAVE_TWENTY_SIX_ENEMIES, 	.typeCount = 1, .timer = 3600},
	{ .types = (GameEntityType*)WAVE_TWENTY_SEVEN_ENEMIES, 	.typeCount = 1, .timer = 3600},
	{ .types = (GameEntityType*)WAVE_TWENTY_EIGHT_ENEMIES, 	.typeCount = 5, .timer = 3600},
	{ .types = (GameEntityType*)WAVE_TWENTY_NINE_ENEMIES, 	.typeCount = 1, .timer = 3600},
	{ .types = (GameEntityType*)WAVE_THIRTY_ENEMIES, 	.typeCount = 6, .timer = 5200}
};

typedef struct ComponentActionWave
{
	ECSComponent component;
	u32 timer;
	u32 index;
	bool isSpawnWave;
} ComponentActionWave;

void component_action_wave_add(ComponentActionWave* self, ECS* ecs);
void component_action_wave_tick(ComponentActionWave* self, ECS* ecs);

static const ECSComponentInfo COMPONENT_ACTION_WAVE_INFO = 
{
	.system = 
	{
		.functions = 
		{ 
			(ECSFunction)component_action_wave_add,
			NULL,
			(ECSFunction)component_action_wave_tick,
			NULL
		}
	},
	.type = ECS_COMPONENT_ACTION_WAVE,
	.size = sizeof(ComponentActionWave)
};


