#pragma once

#include "CoreMinimal.h"

/**
 * Opcodes do CharServer (WebSocket) consumidos pelo cliente. Espelha
 * `Server/ZeusCharServer/src/protocol/CharOpcodes.ts` (faixa 2000-2099).
 *
 * Wire: string = uint16 LE (len) + UTF-8; inteiros LE. O cabeçalho de 32B
 * é responsabilidade do UZeusCharServerSubsystem (Send/OnRawMessage operam
 * sobre o payload já sem header).
 */
namespace ZMMOCharOp
{
	// Autenticação — payload começa com uint8 method (ver ZMMOCharAuthMethod)
	constexpr int32 C_CHAR_AUTH_REQUEST = 2000;
	constexpr int32 S_CHAR_AUTH_OK      = 2001; // string(accountId)+string(user)+uint64(expiresMs)
	constexpr int32 S_CHAR_AUTH_REJECT  = 2002; // uint16(reason)

	// Listagem/criação/seleção de personagem
	constexpr int32 C_CHAR_LIST_REQUEST = 2010; // uint8 hasWorldFilter [+ uint8[16] worldId]
	constexpr int32 S_CHAR_LIST         = 2011;

	constexpr int32 C_CHAR_CREATE       = 2020; // uint8[16] worldId + slot + ...
	constexpr int32 S_CHAR_CREATE_OK    = 2021;
	constexpr int32 S_CHAR_CREATE_REJECT= 2022;

	// Delete agendado (rathena-style two-step)
	constexpr int32 C_CHAR_DELETE_REQUEST     = 2030;
	constexpr int32 S_CHAR_DELETE_ACK         = 2031;
	constexpr int32 C_CHAR_DELETE_ACCEPT      = 2032;
	constexpr int32 S_CHAR_DELETE_ACCEPT_ACK  = 2033;
	constexpr int32 C_CHAR_DELETE_CANCEL      = 2034;
	constexpr int32 S_CHAR_DELETE_CANCEL_ACK  = 2035;

	constexpr int32 C_CHAR_SELECT       = 2040;
	constexpr int32 S_CHAR_SELECT_OK    = 2041;
	constexpr int32 S_CHAR_SELECT_REJECT= 2042;

	// Listagem de mundos (Fase 1 do ARQUITETURA_SERVER_SELECT)
	constexpr int32 C_WORLD_LIST_REQUEST = 2060; // payload vazio
	constexpr int32 S_WORLD_LIST         = 2061; // uint16 count + entries
	/**
	 * Push do CharServer com update de UM mundo (state/pop/queueLen).
	 * Wire: string worldId + uint16 pop + uint16 queueLen + uint8 state
	 */
	constexpr int32 S_WORLD_STATUS_UPDATE = 2062;
}

/**
 * Método de autenticação enviado como uint8 prefix no payload do
 * C_CHAR_AUTH_REQUEST.
 */
namespace ZMMOCharAuthMethod
{
	constexpr uint8 TOKEN    = 0;
	constexpr uint8 PASSWORD = 1;
}

/** Espelha `CharRejectReason` em CharOpcodes.ts. */
namespace ZMMOCharRejectReason
{
	constexpr uint16 Unknown                 = 0;
	constexpr uint16 InvalidToken            = 1;
	constexpr uint16 AccountBanned           = 2;
	constexpr uint16 AlreadyOnline           = 3;
	constexpr uint16 InvalidCredentials      = 4;
	constexpr uint16 AccountLocked           = 5;
	constexpr uint16 AccountSuspended        = 6;
	constexpr uint16 CredentialsAuthDisabled = 7;
	constexpr uint16 WorldOffline            = 8;
	constexpr uint16 WorldMaintenance        = 9;
	constexpr uint16 WorldFull               = 10;
	constexpr uint16 WorldRegionMismatch     = 11;
	constexpr uint16 WorldNotFound           = 12;
	constexpr uint16 NameInUse               = 20;
	constexpr uint16 InvalidName             = 21;
	constexpr uint16 SlotOccupied            = 22;
	constexpr uint16 CharNotFound            = 23;
	constexpr uint16 DeleteScheduled         = 24;
	constexpr uint16 DeleteNotScheduled      = 25;
}

/** Estado do mundo no wire (uint8). Espelha `WireWorldState` em CharOpcodes.ts. */
namespace ZMMOWireWorldState
{
	constexpr uint8 Offline     = 0;
	constexpr uint8 Online      = 1;
	constexpr uint8 Maintenance = 2;
}
