#include "systems.h"

#include "../game_state.h"
#include "../sounds.h"

i32 harvestEvent(ecs_entity_t entity, HarvestEvent event) {
    BZ_ASSERT(ecs_has_id(ECS, entity, Harvestable));
    BZ_ASSERT(ecs_has(ECS, entity, Resource));

    ecs_set(ECS, entity, Easing, {
        .compID = ecs_id(Rotation),
        .memberOffset = 0,
        .easingFunc = BZ_EASE_OUT_ELASTIC,
        .duration = 0.6f,

        // 45 * (1.0f + (-1.0f) * x)
        .target = GetRandomValue(30, 55) * GetRandomValue(1, 2) - 1,
        .easeTarget = -1.0f,
        .easeStart = 1.0f
    });
    SoundState *sounds = ecs_singleton_get_mut(ECS, SoundState);
    soundsPlay(sounds, SOUND_WOOD_PUNCH);

    Resource *res = ecs_get_mut(ECS, entity, Resource);
    event.amount = BZ_MIN(event.amount, res->amount);
    res->amount -= event.amount;

    if (res->amount <= 0)
        ecs_delete(ECS, entity);

    return event.amount;
}

void depositEvent(ecs_entity_t entity, DepositEvent event) {
}
