//
//  PresencePayloadContainer.proto
//  HomeKit
//
//  Created by Daniel Zeng on 3/10/2026.
//  Copyright © 2026 Apple Inc. All rights reserved.
//

// To generate Swift code:
// cd Sources/homed/StatusChannel/Proto/Definitions
// xcrun -sdk iphoneos.internal protoc \
//     -I . \
//     --swift_out=../Generated \
//     --swift_opt=SwiftProtobufModuleName=InternalSwiftProtobuf \
//     --swift_opt=Visibility=Internal \
//     PresencePayloadContainer.proto

edition = "2023";
package apple.homekit.presencepayload;

import "google/protobuf/timestamp.proto";

option swift_prefix = "PresencePayload";

// Resident location state
// ObjC values: Unknown=100, Away=200, AtHome=300
// Serializer converts between ObjC values and proto values
enum ResidentLocation {
  RESIDENT_LOCATION_UNSPECIFIED = 0;
  RESIDENT_LOCATION_UNKNOWN = 1;
  RESIDENT_LOCATION_AWAY = 2;
  RESIDENT_LOCATION_AT_HOME = 3;
}

// Network connection type
// match HMDResidentNetworkConnectionType enum in HMDResidentSelectionInfo.h
enum NetworkConnectionType {
  NETWORK_CONNECTION_TYPE_UNSPECIFIED = 0;
  NETWORK_CONNECTION_TYPE_UNKNOWN = 1;
  NETWORK_CONNECTION_TYPE_ETHERNET = 2;
  NETWORK_CONNECTION_TYPE_WIFI = 3;
}

// Resident selection mode
// match HMDResidentSelectionModeType enum in HMDResidentSelectionInfo.h
enum SelectionModeType {
  SELECTION_MODE_TYPE_UNSPECIFIED = 0;
  SELECTION_MODE_TYPE_UNKNOWN = 1;
  SELECTION_MODE_TYPE_COORDINATION_ELECTION = 2;
  SELECTION_MODE_TYPE_MANUAL_SELECTION = 3;
  SELECTION_MODE_TYPE_AUTO_SELECTION = 4;
}

// Preferred residents list
message PreferredResidentsList {
  // List of preferred resident IDS identifiers (UUID bytes)
  repeated bytes resident_ids_identifiers = 1;

  // When the list was last modified
  google.protobuf.Timestamp modified_timestamp = 2;
}

// Resident selection information
message ResidentSelectionInfo {
  // Timestamp of the selection
  google.protobuf.Timestamp selection_timestamp = 1;

  // Selection mode
  SelectionModeType selection_mode = 2;

  // User-selected preferred resident in manual mode (UUID bytes)
  bytes user_preferred_resident_ids_identifier = 3;
}

// Top-level container for presence payload published to StatusKit
// Wraps the privileged resident election fields plus per-domain serialized data
message PresencePayloadContainer {
    // Device IDS identifier (UUID as 16 bytes)
    bytes device_ids_identifier = 1;

    // When this payload was published
    google.protobuf.Timestamp publish_time = 2;

    // Privileged fields:
    string software_version = 3;
    ResidentLocation location = 4;
    NetworkConnectionType network_connection_type = 5;
    bool has_reachable_accessories = 6;
    string generation_id = 7;
    PreferredResidentsList preferred_residents_list = 8;
    ResidentSelectionInfo selection_info = 9;

    // Domain-specific data pairs: key is HMDResidentStatusChannelDomain value, value is serialized domain payload
    map<int32, bytes> domain_data_pairs = 10;
}
