syntax = "proto3";

package photon.imessage.v1;

import "photon/imessage/v1/location_types.proto";
import "photon/imessage/v1/streaming.proto";

option swift_prefix = "PIMsg_";


// ---------------------------------------------------------------------------
// Service
// ---------------------------------------------------------------------------

// Find My friend-location queries and live updates.
// Reads issue one-shot source queries; the watch stream forwards pushed
// observations and is not server-polled on a timer.
service LocationService {

  rpc ListSharedFriendLocations(ListSharedFriendLocationsRequest)
      returns (ListSharedFriendLocationsResponse);

  rpc GetSharedFriendLocation(GetSharedFriendLocationRequest)
      returns (GetSharedFriendLocationResponse);

  rpc RequestFriendLocationSharing(RequestFriendLocationSharingRequest)
      returns (RequestFriendLocationSharingResponse);

  rpc WatchSharedFriendLocations(WatchSharedFriendLocationsRequest)
      returns (stream WatchSharedFriendLocationsResponse);

}


// ---------------------------------------------------------------------------
// Reads
// ---------------------------------------------------------------------------

message ListSharedFriendLocationsRequest {}


message ListSharedFriendLocationsResponse {

  repeated SharedFriendLocation locations = 1;

}


// Returns the current shared location for one address.
//
// Errors:
//   INVALID_ARGUMENT  malformed address
//   NOT_FOUND         address is valid but not currently sharing a location
message GetSharedFriendLocationRequest {

  string address = 1;

}


message GetSharedFriendLocationResponse {

  SharedFriendLocation location = 1;

}


// ---------------------------------------------------------------------------
// Mutations
// ---------------------------------------------------------------------------

// Sends a visible Find My request card to `address` in `chat_guid`.
// `address` must be a participant in the chat.
//
// Errors:
//   INVALID_ARGUMENT  malformed address/chat_guid, or address is not in chat
//   NOT_FOUND         chat is not visible to the current account
message RequestFriendLocationSharingRequest {

  string chat_guid = 1;

  string address = 2;

  optional string client_message_id = 100;

}


message RequestFriendLocationSharingResponse {

  string address = 1;

  string status = 2;

  optional string reason = 3;

  optional string message_guid = 4;

}


// ---------------------------------------------------------------------------
// Streams
// ---------------------------------------------------------------------------

// Absent `address` = watch every shared location update. Present
// `address` = watch updates for one address only.
message WatchSharedFriendLocationsRequest {

  optional string address = 1;

}


message WatchSharedFriendLocationsResponse {

  oneof payload {

    SharedFriendLocationUpdated location_updated = 10;

    Heartbeat heartbeat = 99;

  }

}
