#include "component_shop.h"

static void _shop_item_init(ComponentShop* self, ECS* ecs);
static void _shop_button_init(ComponentShop* self, ECS* ecs);

/* Initializes shop items. */
static void 
_shop_item_init(ComponentShop* self, ECS* ecs)
{
	entity_shop_item_upgrade_lifetime_init(ecs, self->upgradeLifetimeID, self->affectedID, self->affectedID2);
	entity_shop_item_upgrade_redirects_init(ecs, self->upgradeRedirectsID, self->affectedID, self->affectedID2);
	entity_shop_item_upgrade_ammo_init(ecs, self->upgradeAmmoID, self->affectedID, self->affectedID2);
	entity_shop_item_health_init(ecs, self->healthID, self->affectedID, self->affectedID2);
	entity_shop_item_feed_init(ecs, self->feedID, self->affectedID, self->affectedID2);
}

/* Initializes shop buttons. */
static void 
_shop_button_init(ComponentShop* self, ECS* ecs)
{
	entity_shop_button_init(ecs, self->buttonUpgradeLifetimeID, (f32*)COMPONENT_SHOP_BUTTON_UPGRADE_LIFETIME_POSITION, self->upgradeLifetimeID);
	entity_shop_button_init(ecs, self->buttonUpgradeRedirectsID, (f32*)COMPONENT_SHOP_BUTTON_UPGRADE_REDIRECTS_POSITION, self->upgradeRedirectsID);
	entity_shop_button_init(ecs, self->buttonUpgradeAmmoID, (f32*)COMPONENT_SHOP_BUTTON_UPGRADE_AMMO_POSITION, self->upgradeAmmoID);
	entity_shop_button_init(ecs, self->buttonHealthID, (f32*)COMPONENT_SHOP_BUTTON_HEALTH_POSITION, self->healthID);
	entity_shop_button_init(ecs, self->buttonFeedID, (f32*)COMPONENT_SHOP_BUTTON_FEED_POSITION, self->feedID);
}

/* Sets shop component info. */
void
component_shop_init(ComponentShop* self, ECS* ecs, u32 affectedID, u32 affectedID2)
{
	self->affectedID = affectedID;
	self->affectedID2 = affectedID2;

	_shop_item_init(self, ecs);
	_shop_button_init(self, ecs);
}

/* Runs on addition of component shop entity. */
void
component_shop_add(ComponentShop* self, ECS* ecs)
{
	self->upgradeLifetimeID = ecs_entity_add(ecs);
	self->upgradeRedirectsID = ecs_entity_add(ecs);
	self->upgradeAmmoID = ecs_entity_add(ecs);
	self->healthID = ecs_entity_add(ecs);
	self->feedID = ecs_entity_add(ecs);
	self->buttonUpgradeLifetimeID = ecs_entity_add(ecs);
	self->buttonUpgradeRedirectsID = ecs_entity_add(ecs);
	self->buttonUpgradeAmmoID = ecs_entity_add(ecs);
	self->buttonHealthID = ecs_entity_add(ecs);
	self->buttonFeedID = ecs_entity_add(ecs);
}

/* Runs on deletion of component shop entity. */
void
component_shop_delete(ComponentShop* self, ECS* ecs)
{
	ecs_entity_delete(ecs, self->upgradeLifetimeID);
	ecs_entity_delete(ecs, self->upgradeRedirectsID);
	ecs_entity_delete(ecs, self->upgradeAmmoID);
	ecs_entity_delete(ecs, self->healthID);
	ecs_entity_delete(ecs, self->feedID);
	ecs_entity_delete(ecs, self->buttonUpgradeLifetimeID);
	ecs_entity_delete(ecs, self->buttonUpgradeRedirectsID);
	ecs_entity_delete(ecs, self->buttonUpgradeAmmoID);
	ecs_entity_delete(ecs, self->buttonHealthID);
	ecs_entity_delete(ecs, self->buttonFeedID);
}

/* Ticks component shop. */
void
component_shop_tick(ComponentShop* self, ECS* ecs)
{

}
