/*
Copyright (c) 2024 Rune AI Inc.
All rights reserved.

This code is proprietary to Rune AI Inc.
The code may be used solely for accessing the Service provided by Rune AI Inc. following the Rune AI Inc. Terms of Service ("Terms") accessible at rune.ai/eula. You may not use this code for any use or purpose other than as expressly permitted by the Terms.
Restrictions set forth in the Terms include, but is not limited to, that you may not copy, adapt, modify, prepare derivative works based upon, distribute, license, sell, transfer, publicly display, publicly perform, transmit, stream, broadcast, attempt to discover any source code, reverse engineer, decompile, dissemble, or otherwise exploit the code as a whole or any portion of the code.
*/
type PersistedPlayers<PersistedData> = Record<PlayerId, PersistedData>;
type GameStateWithPersisted<GameState, PersistedData> = GameState & {
    persisted: PersistedPlayers<PersistedData>;
};
type UntypedPersistedData = {};
type UntypedGameState = Record<string, any>;
type UntypedGameStateWithPersisted = GameStateWithPersisted<UntypedGameState, UntypedPersistedData>;
type SessionId = string;
type GameId = number;
type PlayerId = string;
type RandomSeed = number;
type Player = {
    playerId: PlayerId;
    displayName: string;
    avatarUrl: string;
};
type Players = Record<PlayerId, Player>;

type LogInfo = {
    devDash: null;
} | {
    devDash: {
        type: "CLIENT" | "LOGIC";
        userType?: "UNKNOWN" | "PLAYER" | "SPECTATOR";
    };
};

type ServerErrorMessage = keyof typeof errorMap;
declare const errorMap: {
    SERVER_UPDATE_LOOP_FASTER_THAN_GAME_TIME: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    GET_GAME_STATE_FAILED: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    SERVER_RECEIVED_MESSAGE_TOO_BIG: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    SERVER_MESSAGE_TO_CLIENTS_TOO_BIG: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    SERVER_FULL: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    ON_PLAYER_JOINED_CALLBACK_MISSING: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    ROOM_GAME_STATE_MISSING: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    PERSIST_DATA_AFTER_ERROR_NOT_AVAILABLE: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    GET_PERSISTED_STATE_FAILED: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    GAME_END_PERSIST_USER_NOT_FOUND: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    PLAYER_LEFT_NO_USERS_INCORRECT_PERSISTED_PLAYERS: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    PERSISTED_STATE_NOT_ENABLED: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    UPDATE_LOOP_BEHIND_GAME_TIME: {
        devUIMessage: string;
        logInfo: {
            devDash: null;
        };
    };
    AI_PROMPT_REQUEST_FAILED: {
        devUIUnexpected: true;
        logInfo: {
            devDash: null;
        };
    };
    ACTION_PARAMS_SIZE_OVER_LIMIT: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    PLAYER_JOINED_FAILED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    PLAYER_LEFT_FAILED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    AI_PROMPT_RESPONSE_FAILED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    ACTION_TRIGGERED_IN_LOGIC: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    STATE_SYNC_TOO_BIG: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    GAME_OVER_INVALID_OPTIONS: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    SERVER_UPDATE_LOOP_FAILED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    ACTION_FAILED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    SETUP_GAME_OVER_NOT_ALLOWED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    SETUP_FAILED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    PERSISTED_STATE_USED_WITHOUT_FLAG: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    SETUP_PERSISTED_KEY_NOT_ALLOWED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    PERSISTED_NOT_AN_OBJECT: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    PERSISTED_KEY_MISSING: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    PERSISTED_EXTRA_KEY_DETECTED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    PERSISTED_PLAYER_MISSING: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    PERSISTED_PLAYER_NOT_AN_OBJECT: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    PERSISTED_PLAYER_OVER_LIMIT: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    AI_PROMPT_RESPONSE_NOT_DEFINED: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
    AI_PROMPT_REQUEST_PARAM_WRONG_FORMAT: {
        logInfo: LogInfo;
    } & ({
        devUIMessage?: string | ((data: any) => string) | undefined;
        consoleMessage?: string | ((data: any) => string) | undefined;
        printExtraDataInDevUI?: boolean | undefined;
        devUIErrorTitle?: string | undefined;
    } | {
        devUIUnexpected: true;
    });
};

type GameOverResult = "WON" | "LOST" | "TIE" | number;
type GameOverOptions = {
    delayPopUp?: boolean;
    minimizePopUp?: boolean;
} & ({
    players: {
        [playerId: PlayerId]: GameOverResult;
    };
    everyone?: never;
} | {
    players?: never;
    everyone: GameOverResult;
});
type GameOverGameEnded = {
    reason: "gameEnded";
    options: GameOverOptions;
};
type GameOverPlayerLeft = {
    reason: "playerLeft";
};
type GameOverMinPlayers = {
    reason: "minPlayers";
};
type GameOverError = {
    reason: "err";
    err?: {
        message: ServerErrorMessage;
        data?: object;
    };
};
type GameOverContext = (GameOverMinPlayers | GameOverPlayerLeft | GameOverGameEnded | GameOverError) & {
    players: Players;
};

type PlayersRandomState = Record<PlayerId, {
    seed: RandomSeed;
    actionCount: number;
}>;
type GameContext = {
    readonly gameOver: GameOverContext | null;
    orderNumber: number;
    sessionId: SessionId;
    gameId: GameId;
    serverStartedAt: number;
};
type ServerSerializationData<GameStateWithPersisted> = {
    game: GameStateWithPersisted;
} & ServerState;
type ServerState = {
    context: GameContext;
    random: PlayersRandomState;
    gameTime: number;
    updateCount: number;
};

declare function validateServerSerializationData(v: unknown): ServerSerializationData<UntypedGameStateWithPersisted>;

export { validateServerSerializationData };
