#pragma once

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

#include "../stat/component_wave.h"

#include "../../entity/play/entity_chip.h"
#include "../../entity/play/entity_cupper.h"
#include "../../entity/play/entity_custarpedo.h"
#include "../../entity/play/entity_crumbler.h"
#include "../../entity/play/entity_chipper.h"
#include "../../entity/play/entity_excorsant.h"
#include "../stat/component_level.h"

#define COMPONENT_ACTION_SPAWN_TIMER_BASE 100
#define COMPONENT_ACTION_SPAWN_TIMER_LEVEL_MULTIPLIER 10
#define COMPONENT_ACTION_SPAWN_TIMER_MINIMUM 20

#define SPAWN_DIRECTION_COUNT SPAWN_WEST + 1
typedef enum SpawnDirection
{
	SPAWN_DIRECTION_NORTH,
	SPAWN_DIRECTION_EAST,
	SPAWN_DIRECTION_SOUTH,
	SPAWN_DIRECTION_WEST
} SpawnDirection;

#define SPAWN_ENTRY_COUNT SPAWN_EMERGE + 1
typedef enum SpawnEntryType
{
	SPAWN_ENTRY_NONE,
	SPAWN_ENTRY_WANDER,
	SPAWN_ENTRY_FALL,
	SPAWN_ENTRY_EMERGE
} SpawnEntryType;

#define SPAWN_RARITY_COUNT SPAWN_RARITY_RARE + 1
typedef enum SpawnRarityType
{
	SPAWN_RARITY_NONE,
	SPAWN_RARITY_COMMON,
	SPAWN_RARITY_UNCOMMON,
	SPAWN_RARITY_RARE
} SpawnRarityType;

typedef struct SpawnWave
{
	GameEntityType* types;
	u32 typeCount;
	u32 timer;
} SpawnWave;

typedef struct ComponentActionSpawn
{
	ECSComponent component;
	s32 combatTimer;
	s32 timer;
	u32 targetID;
	u32 levelBonus;
	Vector entities; /* u32 */
	Vector types; /* GameEntityType */
	bool isSpawn;
	bool isCombat;
} ComponentActionSpawn;

static const Rectangle SPAWN_OUT_OF_BOUNDS_RECTANGLE = 
{
	.x = 0,
	.y = 0,
	.w = 1920,
	.h = 1080
};

static const Rectangle SPAWN_IN_BOUNDS_RECTANGLE =
{
	.x = 80,
	.y = 80,
	.w = 1820,
	.h = 930
};

static const SpawnRarityType SPAWN_GAME_ENTITY_RARITY_TYPES[GAME_ENTITY_TYPE_COUNT] =
{
	SPAWN_RARITY_NONE,
	SPAWN_RARITY_NONE,
	SPAWN_RARITY_COMMON,
	SPAWN_RARITY_COMMON,
	SPAWN_RARITY_COMMON,
	SPAWN_RARITY_RARE,
	SPAWN_RARITY_COMMON,
	SPAWN_RARITY_UNCOMMON,
	SPAWN_RARITY_UNCOMMON,
	SPAWN_RARITY_RARE,
	SPAWN_RARITY_RARE,
	SPAWN_RARITY_UNCOMMON,
	SPAWN_RARITY_RARE,
	SPAWN_RARITY_NONE,
	SPAWN_RARITY_NONE,
	SPAWN_RARITY_NONE
};

static const SpawnEntryType SPAWN_GAME_ENTITY_ENTRY_TYPES[GAME_ENTITY_TYPE_COUNT] =
{
	SPAWN_ENTRY_NONE,
	SPAWN_ENTRY_NONE,
	SPAWN_ENTRY_WANDER,
	SPAWN_ENTRY_WANDER,
	SPAWN_ENTRY_WANDER,
	SPAWN_ENTRY_FALL,
	SPAWN_ENTRY_WANDER,
	SPAWN_ENTRY_WANDER,
	SPAWN_ENTRY_EMERGE,
	SPAWN_ENTRY_FALL,
	SPAWN_ENTRY_EMERGE,
	SPAWN_ENTRY_FALL,
	SPAWN_ENTRY_WANDER,
	SPAWN_ENTRY_NONE,
	SPAWN_ENTRY_NONE,
	SPAWN_ENTRY_NONE
};

void component_action_spawn_wave_add(ComponentActionSpawn* self, ECS* ecs, const SpawnWave* spawnWave);
void component_action_spawn_init(ComponentActionSpawn* self, u32 targetID);
void component_action_spawn_set(ComponentActionSpawn* self, GameEntityType* types, u32 typeCount);
void component_action_spawn_add(ComponentActionSpawn* self, ECS* ecs);
void component_action_spawn_delete(ComponentActionSpawn* self, ECS* ecs);
void component_action_spawn_tick(ComponentActionSpawn* self, ECS* ecs);

static const ECSComponentInfo COMPONENT_ACTION_SPAWN_INFO = 
{
	.system = 
	{
		.functions = 
		{ 

			(ECSFunction)component_action_spawn_add,
			(ECSFunction)component_action_spawn_delete,
			(ECSFunction)component_action_spawn_tick,
			NULL
		}
	},
	.type = ECS_COMPONENT_ACTION_SPAWN,
	.size = sizeof(ComponentActionSpawn)
};


