#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 ZeusCharOp
{
	// Autenticação — payload começa com uint8 method (ver ZeusCharAuthMethod)
	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 hasRealmFilter [+ uint8[16] realmId]
	constexpr int32 S_CHAR_LIST         = 2011;

	constexpr int32 C_CHAR_CREATE       = 2020; // uint8[16] realmId + 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 Realms (renomeado de WORLD_LIST no refator R4 — Server
	// Meshing). Server-side: `Server/ZeusCharServer/src/services/realm-list.service.ts`.
	constexpr int32 C_REALM_LIST_REQUEST = 2060; // payload vazio
	constexpr int32 S_REALM_LIST         = 2061; // uint16 count + entries
	/**
	 * Push do CharServer com update de UM Realm (state/pop/queueLen).
	 * Wire: string realmId + uint16 pop + uint16 queueLen + uint8 state
	 */
	constexpr int32 S_REALM_STATUS_UPDATE = 2062;
}

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

/** Espelha `CharRejectReason` em CharOpcodes.ts. */
namespace ZeusCharRejectReason
{
	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 RealmOffline            = 8;
	constexpr uint16 RealmMaintenance        = 9;
	constexpr uint16 RealmFull                = 10;
	constexpr uint16 RealmRegionMismatch     = 11;
	constexpr uint16 RealmNotFound           = 12;
	/** Posicao do char nao esta dentro de nenhuma cell do grid_layout do Realm (dead zone). */
	constexpr uint16 CharOutsideAnyCell      = 13;
	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 Realm no wire (uint8). Espelha `WireRealmState` em CharOpcodes.ts. */
namespace ZeusWireRealmState
{
	constexpr uint8 Offline     = 0;
	constexpr uint8 Online      = 1;
	constexpr uint8 Maintenance = 2;
}
