syntax = "proto3";

package proto;

option go_package = "a301_game_server/proto/gen/pb";

// ─── Authentication ────────────────────────────────────────

message LoginRequest {
  string username = 1;
  string password = 2;
}

message LoginResponse {
  bool   success       = 1;
  string session_token = 2;
  string error_message = 3;
  uint64 player_id     = 4;
}

message EnterWorldRequest {
  string session_token = 1;
}

message EnterWorldResponse {
  bool         success       = 1;
  string       error_message = 2;
  EntityState  self          = 3;
  repeated EntityState nearby_entities = 4;
  uint32       zone_id       = 5;
}

// ─── Entity State ──────────────────────────────────────────

message Vector3 {
  float x = 1;
  float y = 2;
  float z = 3;
}

message EntityState {
  uint64  entity_id = 1;
  string  name      = 2;
  Vector3 position  = 3;
  float   rotation  = 4;
  int32   hp        = 5;
  int32   max_hp    = 6;
  int32   level     = 7;
  EntityType entity_type = 8;
}

enum EntityType {
  ENTITY_TYPE_PLAYER = 0;
  ENTITY_TYPE_MOB    = 1;
  ENTITY_TYPE_NPC    = 2;
}

// ─── Movement ──────────────────────────────────────────────

message MoveRequest {
  Vector3 position  = 1;
  float   rotation  = 2;
  Vector3 velocity  = 3;
}

message StateUpdate {
  repeated EntityState entities = 1;
  int64 server_tick = 2;
}

message SpawnEntity {
  EntityState entity = 1;
}

message DespawnEntity {
  uint64 entity_id = 1;
}

// ─── System ────────────────────────────────────────────────

message Ping {
  int64 client_time = 1;
}

message Pong {
  int64 client_time = 1;
  int64 server_time = 2;
}

// ─── Zone Transfer ─────────────────────────────────────────

message ZoneTransferNotify {
  uint32      new_zone_id = 1;
  EntityState self        = 2;
  repeated EntityState nearby_entities = 3;
}

// ─── Combat ────────────────────────────────────────────────

message UseSkillRequest {
  uint32 skill_id   = 1;
  uint64 target_id  = 2;
  Vector3 target_pos = 3;  // for ground-targeted AoE
}

message UseSkillResponse {
  bool   success       = 1;
  string error_message = 2;
}

message CombatEvent {
  uint64 caster_id    = 1;
  uint64 target_id    = 2;
  uint32 skill_id     = 3;
  int32  damage       = 4;
  int32  heal         = 5;
  bool   is_critical  = 6;
  bool   target_died  = 7;
  int32  target_hp    = 8;
  int32  target_max_hp = 9;
  CombatEventType event_type = 10;
}

enum CombatEventType {
  COMBAT_EVENT_DAMAGE = 0;
  COMBAT_EVENT_HEAL   = 1;
  COMBAT_EVENT_BUFF   = 2;
  COMBAT_EVENT_DEBUFF = 3;
  COMBAT_EVENT_DEATH  = 4;
  COMBAT_EVENT_RESPAWN = 5;
}

message BuffApplied {
  uint64 target_id   = 1;
  uint32 buff_id     = 2;
  string buff_name   = 3;
  float  duration    = 4;
  bool   is_debuff   = 5;
}

message BuffRemoved {
  uint64 target_id   = 1;
  uint32 buff_id     = 2;
}

message RespawnRequest {}

message RespawnResponse {
  EntityState self = 1;
}

// ─── Admin / Debug ─────────────────────────────────────────

message AOIToggleRequest {
  bool enabled = 1;
}

message AOIToggleResponse {
  bool enabled = 1;
  string message = 2;
}

message ServerMetrics {
  int32 online_players  = 1;
  int32 total_entities  = 2;
  int64 tick_duration_us = 3;
  bool  aoi_enabled     = 4;
}

message MetricsRequest {}
