// Message wrapper

enum MessageType {
  DeviceAbsentMessage        = 1;
  DeviceHeartbeatMessage     = 28;
  DeviceIdentityMessage      = 2;
  DeviceLogcatEntryMessage   = 3;
  DeviceLogMessage           = 4;
  DevicePokeMessage          = 5;
  DevicePresentMessage       = 6;
  DevicePropertiesMessage    = 7;
  DeviceRegisteredMessage    = 8;
  DeviceStatusMessage        = 9;
  GroupMessage               = 10;
  JoinGroupMessage           = 11;
  KeyDownMessage             = 12;
  KeyPressMessage            = 13;
  KeyUpMessage               = 14;
  LeaveGroupMessage          = 15;
  LogcatApplyFiltersMessage  = 16;
  ProbeMessage               = 17;
  ShellCommandMessage        = 18;
  ShellKeepAliveMessage      = 19;
  TapMessage                 = 20;
  TouchDownMessage           = 21;
  TouchMoveMessage           = 22;
  TouchUpMessage             = 23;
  TransactionDoneMessage     = 24;
  TransactionProgressMessage = 25;
  TypeMessage                = 26;
  UngroupMessage             = 27;
}

message Envelope {
  required MessageType type = 1;
  required bytes message = 2;
  optional string channel = 3;
}

message TransactionProgressMessage {
  required string serial = 1;
  required uint32 seq = 2;
  optional string data = 3;
}

message TransactionDoneMessage {
  required string serial = 1;
  required uint32 seq = 2;
  required bool success = 3;
  optional string data = 4;
}

// Heartbeat

message DeviceHeartbeatMessage {
  required string serial = 1;
}

// Logging

message DeviceLogMessage {
  required string serial = 1;
  required double timestamp = 2;
  required uint32 priority = 3;
  required string tag = 4;
  required uint32 pid = 5;
  required string message = 6;
  required string identifier = 7;
}

// Introductions

message ProviderMessage {
  required string channel = 1;
  required string name = 2;
}

message DevicePresentMessage {
  required string serial = 1;
  required DeviceStatus status = 2;
  required ProviderMessage provider = 3;
}

message DeviceRegisteredMessage {
  required string serial = 1;
}

message DeviceAbsentMessage {
  required string serial = 1;
}

message DevicePokeMessage {
  required string serial = 1;
  required string channel = 2;
}

message ProbeMessage {
}

enum DeviceStatus {
  OFFLINE = 1;
  UNAUTHORIZED = 2;
  ONLINE = 3;
}

message DeviceStatusMessage {
  required string serial = 1;
  required DeviceStatus status = 2;
}

message DeviceDisplayMessage {
  required uint32 id = 1;
  required uint32 width = 2;
  required uint32 height = 3;
  required uint32 orientation = 4;
  required uint32 xdpi = 5;
  required uint32 ydpi = 6;
  required double fps = 7;
  required double density = 8;
  required bool secure = 9;
  required string url = 10;
}

message DeviceIdentityMessage {
  required string serial = 1;
  required string platform = 2;
  required string manufacturer = 3;
  optional string operator = 4;
  required string model = 5;
  required string version = 6;
  required string abi = 7;
  required string sdk = 8;
  required DeviceDisplayMessage display = 9;
}

message DeviceProperty {
  required string name = 1;
  required string value = 2;
}

message DevicePropertiesMessage {
  required string serial = 1;
  repeated DeviceProperty properties = 2;
}

// Grouping

enum RequirementType {
  SEMVER = 1;
  GLOB = 2;
  EXACT = 3;
}

message DeviceRequirement {
  required string name = 1;
  required string value = 2;
  required RequirementType type = 3;
}

message OwnerMessage {
  required string email = 1;
  required string name = 2;
  required string group = 3;
}

message GroupMessage {
  required OwnerMessage owner = 1;
  required uint32 timeout = 2;
  repeated DeviceRequirement requirements = 3;
}

message UngroupMessage {
  repeated DeviceRequirement requirements = 2;
}

message JoinGroupMessage {
  required string serial = 1;
  required OwnerMessage owner = 2;
}

message LeaveGroupMessage {
  required string serial = 1;
  required OwnerMessage owner = 2;
}

// Input

message TouchDownMessage {
  required uint32 x = 1;
  required uint32 y = 2;
}

message TouchMoveMessage {
  required uint32 x = 1;
  required uint32 y = 2;
}

message TouchUpMessage {
  required uint32 x = 1;
  required uint32 y = 2;
}

message TapMessage {
  required uint32 x = 1;
  required uint32 y = 2;
}

message TypeMessage {
  required string text = 1;
}

enum KeyCode {
  HOME        = 3;
  BACK        = 4;
  BACKSPACE   = 8;
  ENTER       = 13;
  CAPS_LOCK   = 20;
  ESC         = 27;
  PAGE_UP     = 33;
  PAGE_DOWN   = 34;
  MOVE_END    = 35;
  MOVE_HOME   = 36;
  LEFT_ARROW  = 37;
  UP_ARROW    = 38;
  RIGHT_ARROW = 39;
  DOWN_ARROW  = 40;
  INSERT      = 45;
  DELETE      = 46;
  MENU        = 93;
  F1          = 112;
  F2          = 113;
  F3          = 114;
  F4          = 115;
  F5          = 116;
  F6          = 117;
  F7          = 118;
  F8          = 119;
  F9          = 120;
  F10         = 121;
  F11         = 122;
  F12         = 123;
  NUM_LOCK    = 144;
}

message KeyDownMessage {
  required KeyCode keyCode = 1;
}

message KeyUpMessage {
  required KeyCode keyCode = 1;
}

message KeyPressMessage {
  required KeyCode keyCode = 1;
}

// Output

message DeviceLogcatEntryMessage {
  required string serial = 1;
  required double date = 2;
  required uint32 pid = 3;
  required uint32 tid = 4;
  required uint32 priority = 5;
  required string tag = 6;
  required string message = 7;
}

message LogcatFilter {
  required string tag = 1;
  required uint32 priority = 2;
}

message LogcatApplyFiltersMessage {
  repeated LogcatFilter filters = 1;
}

// Commands

message ShellCommandMessage {
  required string command = 1;
  required uint32 timeout = 2;
}

message ShellKeepAliveMessage {
  required uint32 timeout = 1;
}
