syntax = "proto3";

option csharp_namespace = "Leica.Spider.LoggingServer.Reporting";

import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "logging_management.proto";

package spider.loggingserver.reporting;

message RoverConnectionViewModel {
    string connection_id = 1;
    string sbc_subscription_id = 2;
    int32 sbc_credential_id = 3;
    int32 sbc_user_id = 4;
    string sbc_credential_user_name = 5;
    string sbc_user_name = 6;

    google.protobuf.Timestamp start_time = 7;
    google.protobuf.Timestamp end_time = 8;
    spider.loggingserver.logging.DisconnectReason disconnect_reason = 9;
    string ntrip_user_agent = 10;

    google.protobuf.Duration time_to_first_data = 11;
    google.protobuf.Duration no_data_time = 12;
    google.protobuf.Duration single_base_time = 13;
    google.protobuf.Duration network_corrections_time = 14;

    bool has_detailed_connection_log = 15;
    double longitude = 16;
    double latitude = 17;
    double height = 18;
    string rtk_server_host_name = 19;

    repeated RoverConnectionEventViewModel events = 20;
}

message RoverConnectionEventViewModel {
    string id = 1;
    google.protobuf.Timestamp event_time = 2;
    bool isAcknowledged = 3;
    int32 event_type_id = 4;

    int32 rover_count = 5;
    string target_coordinate_system_name = 8;
    int32 target_coordinate_system_id = 9;
    int32 grid_id = 10;
    int32 disconnect_time = 11;
    int32 distance = 12;
    string rover_client_host_info = 13;
    string rejected_clients = 14;
    string device_token = 15;

    RoverConnectionEventStatusViewModel rover_connection_event_status = 16;
}

message SatellitesViewModel {
    uint32 GpsSatelliteCount = 1;
    uint32 GlonassSatelliteCount = 2;
    uint32 GalileoSatelliteCount = 3;
    uint32 BeiDouSatelliteCount = 4;
    uint32 QzssSatelliteCount = 5;
}

message RoverConnectionEventStatusViewModel {
    string connection_event_status_id = 1;

    SatellitesViewModel fixed_ref_satellites = 2;
    SatellitesViewModel used_fkp_satellites = 3;
    SatellitesViewModel rover_satellites = 4;

    int32 positionQuality = 5;
    double hdop = 6;
    string position = 7; // Geometries.Point is not directly supported in protobuf, so it's represented as string
    int32 refStationId = 8;
}

message RoverConnectionSummaryViewModel {
    google.protobuf.Timestamp day = 1;
    google.protobuf.Duration total_duration = 2;
    int32 private_error_log_count = 3;
    int32 public_error_log_count = 4;
}

message EventTypeDefinitionViewModel {
    int32 eventId = 1;
    string text = 2;
    bool is_rover_notification = 3;
    EventTypeGroup event_type_group = 4;
}

message OpenApiQueryListRequestOptions {
    /**
     * Whether to include the total number of items in the result set before paging
     */
    optional bool count = 1;

    /**
     * Which navigation properties to include in the result set.
     * See https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionexpand
     */
    repeated string expand = 2;

    /**
     * A filter to select only a subset of the overall results.
     * See https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionfilter
     */
    string filter = 3;

    /**
     * A comma separated list of properties to sort the result set.
     * See https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionorderby
     */
    string orderBy = 4;

    // Select option not available on purpose.

    /**
     * The number of elements to include from the result set for paging.
     * See https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionstopandskip
     */
    optional int32 skip = 5;

    /**
     * The number of elements to include from the result set for paging.
     * See https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionstopandskip
     */
    optional int32 top = 6;
}

message OpenApiQuerySingleRequestOptions {
    /**
     * Which navigation properties to include in the result set.
     * See https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_SystemQueryOptionexpand
     */
    repeated string expand = 1;
}

message LoadConnectionsSpecialFilters {
    // optimized data filters
    repeated int32 filter_by_sbc_user_id = 1;
    repeated int32 filter_by_sbc_credential_id = 2;
    repeated string filter_by_subscription_id = 3;
    repeated int32 filter_by_event_type = 4;
    EventTypeGroup filter_by_event_type_group = 5;
    bool filter_by_having_error_logs = 6;
}

message UserInfo {
    string company_name = 1;
}

message ExtraMappings {
    map<int32, UserInfo> user_mappings = 1;
}

message StreamConnectionsRequest {
    OpenApiQueryListRequestOptions options = 1;
    LoadConnectionsSpecialFilters special_filters = 2;
    ExtraMappings mappings = 3;
}
message GetConnectionSearchEntriesRequest {
    OpenApiQueryListRequestOptions options = 1;
    LoadConnectionsSpecialFilters special_filters = 2;
}

message StreamConnectionResponse {
    RoverConnectionViewModel connection = 1;
}

message GetConnectionSearchEntriesResponse {
    repeated string sbc_subscription_search_entries = 1;
    repeated string sbc_user_name_search_entries = 2;
    repeated string ntrip_user_agent_search_entries = 3;
    repeated string sbc_credential_name_search_entries = 4;
}

message GetConnectionRequest {
    string connection_id = 1;
    OpenApiQuerySingleRequestOptions options = 2;
}

message GetDetailedConnectionLogRequest {
    string connection_id = 1;
}

message GetDetailedConnectionLogResponse {
    bytes gzip_compressed_connection_log_xml = 1;
}

message GetConnectionResponse {
    RoverConnectionViewModel connection = 1;
}

message AcknowledgeConnectionEventsRequest {
    repeated string connection_event_ids = 1;
}

message AcknowledgeConnectionEventsResponse {
    int32 number_of_acknowledged_events = 1;
}

enum EventTypeGroup {
    IGNORE = 0;
    NO_ERROR = 1;
    PUBLIC_ERROR = 2;
    PRIVATE_ERROR = 3;
}

message GetRoverErrorLogsAndConnectionTimeSummaryRequest {
    LoadConnectionsSpecialFilters special_filters = 1;
    google.protobuf.Timestamp start_time = 2;
    google.protobuf.Timestamp end_time = 3;
    EventTypeGroup event_type_group = 4;
    string timezone_id = 5;
}

message GetRoverErrorLogsAndConnectionTimeSummaryResponse {
    repeated RoverConnectionSummaryViewModel days = 1;
}

message GetConnectionSummaryConsumptionRequest {
    LoadConnectionsSpecialFilters special_filters = 1;
    google.protobuf.Timestamp start_time = 2;
    google.protobuf.Timestamp end_time = 3;
    EventTypeGroup event_type_group = 4;
}

message GetConnectionSummaryConsumptionResponse {
    map<int32, google.protobuf.Duration> durationByCredentials = 1;
}

message GetDetailedConnectionLogReportRequest {
    LoadConnectionsSpecialFilters special_filters = 1;
    google.protobuf.Timestamp start_time = 2;
    google.protobuf.Timestamp end_time = 3;
}

message GetDetailedConnectionLogReportMainResponse {
    int32 amount_users = 1;
    int32 amount_connections = 2;
    google.protobuf.Duration connection_time = 3;
    repeated string subscriptions = 4;
}

message GetDetailedConnectionLogReportKpisResponse {
    google.protobuf.Duration connection_time = 1;
    google.protobuf.Duration total_time_to_first_data = 2;
    google.protobuf.Duration total_no_data_time = 3;
    google.protobuf.Duration total_single_base_time = 4;
    google.protobuf.Duration total_network_corrections_time = 5;
}

message GetEventTypeListRequest {
     string language = 1;
    EventTypeGroup event_type_group = 2;
}

message GetEventTypeListResponse {
    repeated EventTypeDefinitionViewModel event_type_definitions = 1;
}

message ColumnSearch {
    map<string, string> search = 1;
}

service RawConnectionReporting {
    rpc StreamConnections(StreamConnectionsRequest) returns (stream StreamConnectionResponse);
    rpc GetConnectionSearchEntries(GetConnectionSearchEntriesRequest) returns (stream GetConnectionSearchEntriesResponse);
    rpc GetConnection (GetConnectionRequest) returns (GetConnectionResponse);
    rpc GetDetailedConnectionLog (GetDetailedConnectionLogRequest) returns (GetDetailedConnectionLogResponse);
    rpc AcknowledgeConnectionEvents (AcknowledgeConnectionEventsRequest) returns (AcknowledgeConnectionEventsResponse);
    rpc GetRoverErrorLogsAndConnectionTimeSummary (GetRoverErrorLogsAndConnectionTimeSummaryRequest) returns (GetRoverErrorLogsAndConnectionTimeSummaryResponse);
    rpc GetConnectionSummaryConsumption (GetConnectionSummaryConsumptionRequest) returns (GetConnectionSummaryConsumptionResponse);
    rpc GetDetailedConnectionLogReportMain (GetDetailedConnectionLogReportRequest) returns (GetDetailedConnectionLogReportMainResponse);
    rpc GetDetailedConnectionLogReportKpis (GetDetailedConnectionLogReportRequest) returns (GetDetailedConnectionLogReportKpisResponse);
    rpc GetEventTypeList (GetEventTypeListRequest) returns (GetEventTypeListResponse);
}
