export type Message = {
    session?: string
    id?: string
    type: MessageType
    data?: CommandResult | CommandOutput
}
    | InputMessage
    | SaveFileMessage
    | SessionStartMessage
    | SessionUpdateMessage

export type MessageType = "error" | "input" | "output" | "commands" | "save-file"
    | "game:start"
    | "stream:start" | "stream:end" | "stream:append" | "stream:replace"
    | "ui:mode"

export type CommandOutput = string | string[]
    | { text: string, script?: string }
    | { html: string, script?: string }
    | { script: string }
    | { game: string }

export type CommandResult = {
    status: "ok" | "error"
    output: CommandOutput
}

export type InputMessage = {
    type: "input"
    id: string
    session: string
    data: CommandResult | CommandOutput
}

export type SaveFileMessage = {
    type: "save-file"
    id: string
    session: string
    data: CommandResult | CommandOutput
}

export type SessionStartMessage = {
    type: "session:start"
    data: {
        NOSE_DIR: string
        project: string
        cwd: string
        mode: string
    }
}

export type SessionUpdateMessage = {
    type: "session:update"
    data: Record<string, string>
}
