// Copyright (c) 2022 Boston Dynamics, Inc.  All rights reserved.
//
// Downloading, reproducing, distributing or otherwise using the SDK Software
// is subject to the terms and conditions of the Boston Dynamics Software
// Development Kit License (20191101-BDSDK-SL).

syntax = "proto3";

option java_outer_classname = "DirectoryProto";

import "bosdyn/api/header.proto";
import "google/protobuf/timestamp.proto";

package bosdyn.api;

// A message representing a discoverable service.  By definition, all services
// discoverable by this system are expected to be grpc "services" provided by
// some server.
message ServiceEntry {

    // The unique user-friendly name of this service.
    string name = 1;

    // The type of this service. Usually identifies the underlying implementation.
	// Does not have to be unique among all ServiceEntry objects.
    string type = 2;

    // Information used to route to the desired Service. Can either be a full address
    // (aService.spot.robot) or just a DNS label that will be automatically converted to an
    // address (aService).
    string authority = 3;

    // Last update time in robot timebase for this service record. This serves as the time of
    // the last heartbeat to the robot.
    google.protobuf.Timestamp last_update = 4;

    // If 'user_token_required' field is true, any requests to this service must contain
    // a user token for the machine.  Requests without a user token will result in a
    // 401. Most services will want to require a user_token, but ones like auth_service
    // do not.
    bool user_token_required = 5;


    // DEPRECATED as of 2.1.0: The application_token_required field has been removed and is not required anymore.
    // Authorization checks were updated in 1.2.
    reserved "application_token_required";
    reserved 6;

    // If 'permission_required' field is non-empty, any requests to this service must
    // have the same string in the "per" claim of the user token.
    string permission_required = 7;

    // Number of seconds to wait between heartbeats before assuming service in no longer live
    // If unset (0) liveness checks will be disabled for this service.
    double liveness_timeout_secs = 8;

    // The GUID of the payload that this service was registered from. An empty string represents a
    // service that was registered via a client using standard user credentials or internal to the
    // robot. This value is set automatically based on the user token and cannot be set or updated
    // via the API, so it should not be populated by the client at registration time.
    string host_payload_guid = 9;
}

// A message containing information that allows a client to identify a
// given endpoint host using an ip and a port.
message Endpoint {
    // The IP address of the computer hosting this endpoint.
    string host_ip = 1;

    // The port number on which the endpoint is provided, between 0 and 65535.
    int32 port = 2;
}

// The GetServiceEntry request message sends the service name to the robot.
message GetServiceEntryRequest {
    // Common request header.
    RequestHeader header = 1;

    // The unique user-friendly name of the service.
    string service_name = 2;
}

// The GetServiceEntry response message returns a ServiceEntry for the desired service name.
message GetServiceEntryResponse {
    // Common response Header.
    ResponseHeader header = 1;

    enum Status {
        // UNKNOWN should never be used. An internal DirectoryService issue has happened if UNKNOWN is set.
        STATUS_UNKNOWN = 0;

        // GetService was successful. The service_entry field is filled out.
        STATUS_OK = 1;

        // GetService failed because the requested service name does not exist.
        STATUS_NONEXISTENT_SERVICE = 2;
    }
    // Current status of the request.
    Status status = 2;

    // The record for the discovered service.  Only set if 'status' field == STATUS_OK.
    ServiceEntry service_entry = 3;
}

// The ListServiceEntries request message will ask the robot for all services.
message ListServiceEntriesRequest {
    // Common request header.
    RequestHeader header = 1;
}

// The ListServiceEntries response message returns all known services at the time the request
// was recieved.
message ListServiceEntriesResponse {
    // Common response header.
    ResponseHeader header = 1;

    // The resources managed by the LeaseService.
    repeated ServiceEntry service_entries = 2;
}

