from .olives_abstractcontrollableobject import AbstractControllableObject
from olives_objectcontrollable import ObjectControllable
from olives_job import Job
from olives_gamestate import GameState

food_values = {
    'small': 15,
    'medium': 30,
    'big': 70
}


def eat_food(self: AbstractControllableObject, job: Job, game_state: GameState, elapsed_ticks: int, obj: ObjectControllable, parameter: str):
    current_step = job.get_step().get_current_step()
    if current_step == 0:
        # navigate to the context object and set the appropriate animation when done (successfully)
        def success_callback() -> bool:
            game_state.set_animation(self.object_id, "eat", True)
            return True
        self.handle_context_transition_step(job, game_state, obj, success_callback)

    elif current_step == 1:
        # reset if necessary, as well as reduce the funds for this action
        self.reset_step_progress(job, game_state, job.get_step().get_price())
        # determine the overall target progress for this step
        # if there is a badly configured parameter default to a small one
        value = food_values[parameter] if parameter in food_values.keys() else food_values['small']
        # update the elapsed ticks
        self.update_elapsed_ticks(job, elapsed_ticks)
        # get the progress value to add
        obj.set_hunger(obj.get_hunger() + self.get_relative_progress_limited(job, elapsed_ticks, value))
        # and see if we have finished the step already. if so, finish the job
        self.check_for_completion(job)

