#include "character/states/CharacterStateBase.h"
#include "character/CharacterObject.h"
#include "character/CharacterStateMachine.h"

namespace frostbite2D {

CharacterStateBase::CharacterStateBase(CharacterStateId stateId)
    : stateId_(stateId) {
}

CharacterStateId CharacterStateBase::GetId() const {
  return stateId_;
}

void CharacterStateBase::ChangeState(CharacterStateMachine& machine,
                                     CharacterStateContext& context,
                                     CharacterStateId nextState) const {
  machine.ChangeState(context.owner, nextState);
}

void CharacterStateBase::InvokeHook(CharacterStateMachine& machine,
                                    CharacterObject& owner,
                                    const CharacterActionDefinition* action,
                                    const char* phase) const {
  machine.InvokeStateHook(owner, action, phase);
}

bool CharacterStateBase::TryStartAction(CharacterStateMachine& machine,
                                        CharacterStateContext& context,
                                        const std::string& actionId) const {
  return machine.TryStartAction(context.owner, context.commandBuffer, actionId, actionId);
}

bool CharacterStateBase::TryStartAction(CharacterStateMachine& machine,
                                        CharacterStateContext& context,
                                        const std::string& requestedActionId,
                                        const std::string& actionId) const {
  return machine.TryStartAction(
      context.owner, context.commandBuffer, requestedActionId, actionId);
}

bool CharacterStateBase::StartAction(CharacterStateMachine& machine,
                                     CharacterStateContext& context,
                                     const std::string& actionId) const {
  return machine.StartAction(context.owner, actionId, actionId);
}

bool CharacterStateBase::StartAction(CharacterStateMachine& machine,
                                     CharacterStateContext& context,
                                     const std::string& requestedActionId,
                                     const std::string& actionId) const {
  return machine.StartAction(context.owner, requestedActionId, actionId);
}

bool CharacterStateBase::TryStartRegisteredAction(CharacterStateMachine& machine,
                                                  CharacterStateContext& context) const {
  return machine.TryStartRegisteredAction(context);
}

const CharacterActionDefinition* CharacterStateBase::GetCurrentAction(
    const CharacterStateMachine& machine) const {
  return machine.currentAction_;
}

const std::string& CharacterStateBase::GetCurrentActionId(
    const CharacterStateMachine& machine) const {
  return machine.currentActionId_;
}

void CharacterStateBase::SetCurrentAction(CharacterStateMachine& machine,
                                          const CharacterActionDefinition* action,
                                          const std::string& actionId) const {
  machine.currentAction_ = action;
  machine.currentActionId_ = actionId;
}

void CharacterStateBase::ClearCurrentAction(CharacterStateMachine& machine) const {
  machine.currentAction_ = nullptr;
  machine.currentActionId_.clear();
}

float& CharacterStateBase::StateTime(CharacterStateMachine& machine) const {
  return machine.stateTime_;
}

} // namespace frostbite2D
