import { IPlayerData, LevelInitializer } from "../../game/levels";

export const START_EXECUTING = "START_EXECUTING"
export const PAUSE_EXECUTION = "PAUSE_EXECUTION"
export const STEP_EXECUTION = "STEP_EXECUTION"
export const TOGGLE_SPEED = "TOGGLE_SPEED"
export const TOGGLE_AUTOSTEP = "TOGGLE_AUTOSTEP"
export const RESET_EXECUTION = "RESET_EXECUTION"
export const WON_LEVEL = "WON_LEVEL"


export interface ip { fn: string, fnIdx: number }

export interface ExecutionState {
    running: boolean,
    autostep: boolean,
    instructionPtr: ip,
    callStack: Array<ip>,
    instruction?: string,
    playerPos: IPlayerData,
    fast: boolean,
    finished: boolean,
    won: boolean,
    code: { [key: string]: Array<string> },
    level?: LevelInitializer

}

export interface startExecutionAction {
    type: typeof START_EXECUTING,
    playerPos: IPlayerData,
    code: Array<Array<string>>,
    level: LevelInitializer
}

export interface pauseExecutionAction {
    type: typeof PAUSE_EXECUTION
}

export interface stepExecutionAction {
    type: typeof STEP_EXECUTION
}

export interface toggleSpeedAction {
    type: typeof TOGGLE_SPEED
}

export interface toggleAutoStepAction {
    type: typeof TOGGLE_AUTOSTEP
}

export interface resetExecutionAction {
    type: typeof RESET_EXECUTION
}

export interface wonLevelAction {
    type: typeof WON_LEVEL
}

export type ExecutionStateActionTypes =
    startExecutionAction
    | pauseExecutionAction
    | stepExecutionAction
    | toggleSpeedAction
    | toggleAutoStepAction
    | resetExecutionAction
    | wonLevelAction
