syntax = "proto3";

package api;

option go_package = "github.com/chirpstack/chirpstack/api/go/v4/api";
option java_package = "io.chirpstack.api";
option java_multiple_files = true;
option java_outer_classname = "RelayProto";
option csharp_namespace = "Chirpstack.Api";
option php_namespace = "Chirpstack\\Api";
option php_metadata_namespace = "GPBMetadata\\Chirpstack\\Api";

import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";

// RelayService is the service providing API methos for managing relays.
service RelayService {
    // List lists the relays for the given application id.
    rpc List(ListRelaysRequest) returns (ListRelaysResponse) {
        option(google.api.http) = {
            get: "/api/relays"
        };
    }

    // AddDevice adds the given device to the relay.
    rpc AddDevice(AddRelayDeviceRequest) returns (google.protobuf.Empty) {
        option(google.api.http) = {
            post: "/api/relays/{relay_dev_eui}/devices"
            body: "*"
        };
    }

    // RemoveDevice removes the given device from the relay.
    rpc RemoveDevice(RemoveRelayDeviceRequest) returns (google.protobuf.Empty) {
        option(google.api.http) = {
            delete: "/api/relays/{relay_dev_eui}/devices/{dev_eui}"
        };
    };

    // ListDevices lists the devices for the given relay.
    rpc ListDevices(ListRelayDevicesRequest) returns (ListRelayDevicesResponse) {
        option(google.api.http) = {
            get: "/api/relays/{relay_dev_eui}/devices"
        };
    };
}

message RelayListItem {
    // DevEUI (EUI64).
    string dev_eui = 1;

    // Name.
    string name = 2;
}

message ListRelaysRequest {
    // Max number of devices to return in the result-set.
    // If not set, it will be treated as 0, and the response will only return the total_count.
    uint32 limit = 1;

    // Offset in the result-set (for pagination).
    uint32 offset = 2;

    // Application ID (UUID).
    string application_id = 3;
}

message ListRelaysResponse {
    // Total number of relays.
    uint32 total_count = 1;

    // Result-set.
    repeated RelayListItem result = 2;
}

message AddRelayDeviceRequest {
    // Relay DevEUI (EUI64).
    string relay_dev_eui = 1;

    // Device DevEUI (EUI64).
    string device_dev_eui = 2;

}

message RemoveRelayDeviceRequest {
    // Relay DevEUI (EUI64).
    string relay_dev_eui = 1;

    // Device DevEUI (EUI64).
    string device_dev_eui = 2;
}

message ListRelayDevicesRequest {
    // Max number of multicast groups to return in the result-set.
    // If not set, it will be treated as 0, and the response will only return the total_count.
    uint32 limit = 1;

    // Offset in the result-set (for pagination).
    uint32 offset = 2;

    // Relay DevEUI (EUI64).
    string relay_dev_eui = 3;
}

message RelayDeviceListItem {
    // DevEUI (EUI64).
    string dev_eui = 1;

    // Created at timestamp.
    google.protobuf.Timestamp created_at = 2;

    // Device name.
    string name = 3;
}

message ListRelayDevicesResponse {
    // Total number of devices.
    uint32 total_count = 1;

    // Result-set.
    repeated RelayDeviceListItem result = 2;
}
