#ifndef TOPDOWN_PLAYER_H
#define TOPDOWN_PLAYER_H 

#include "sprite.h"
#include "spritesheet.h"
#include "sprite_entity.h"
#include "drop.h"
#include "behaviour_entity.h"
#include "state_machine.h"
#include "transformable.h"
#include "player_input.h"

typedef struct Player {
    Transform transform;

    PlayerInput* input;
    Vector input_direction;

    unsigned short faceDirection;

    StateMachine* animationStateMachine;
    size_t animFrame;
    float animFrameTimer;
    float animFrameInterval;
    
    Spritesheet* walk;
    Spritesheet* stand;

    Sprite* sprite;
} Player;

extern Player* MakePlayer();

extern Player* SpawnPlayer(Vector location);
extern void PlayerUpdate(Player* self, float deltaTime);
extern void PlayerStart(Player* self);
extern void PlayerDestroy(Player* self);
extern void PlayerDraw(Player* self);

extern void PlayerInputHorizontal(Player* self, InputEvent event);
extern void PlayerInputVertical(Player* self, InputEvent event);

extern Sprite* PlayerGetSprite(Player* self);
extern Transform* PlayerGetTransform(Player* self);

impl_Drop_for(Player,
    PlayerDestroy
)

impl_Transformable_for(Player, 
    PlayerGetTransform
)

impl_BehaviourEntity_for(Player,
    PlayerStart,
    PlayerUpdate,
    SpawnPlayer,
    PlayerDraw
)

impl_SpriteEntity_for(Player,
    PlayerGetSprite
)

extern const State* PlayerAnimationUpdate(Player* player, float deltaTime);
extern void PlayerAnimationExit(Player* player);

extern void PlayerIdleEnter(Player* player);
extern const State* PlayerIdleUpdate(Player* player, float deltaTime);

DefineState(PlayerIdle, Player,
    PlayerIdleEnter,
    PlayerAnimationExit,
    PlayerIdleUpdate
)

#endif // !TOPDOWN_PLAYER_H
