#pragma once

#include <Critical.h>
#include <Either.h>
#include <Model3D.h>

#include "Area.h"
#include "EntityType.h"
#include "FactoryCraftModel.h"

class Block;

struct MovementFrame
{
    Framework::Vec3<float> direction;
    Framework::Vec3<float> targetPosition;
    int movementFlags = 0;
    double duration = 0;
};

class Entity : public FactoryCraftModel
{
private:
    int id;
    const EntityType* zType;
    Framework::Critical cs;
    bool playerControlled;
    float maxMovementSpeed;
    int lastFlags;
    double timeSinceSync;
    Framework::Vec3<float> lastDirection;
    Framework::Array<MovementFrame> movements;
    Framework::Vec3<float> speed;
    MovementFrame currentFrame;

public:
    Entity(const EntityType* zType,
        Framework::Model3DData* model,
        Framework::Model3DTextur* texture,
        int id,
        Framework::Vec3<float> position,
        float maxMovementSpeed);
    ~Entity();

    void api(char* message);
    bool tick(double time) override;

    int getId() const;
    const EntityType* zEntityType() const;
    void lock();
    void unlock();
    void setPlayerControlled();
};