syntax = "proto3";

import "google/protobuf/struct.proto";

package observer;

service ObserverAuthentication {
    rpc Authenticate(AuthenticationRequest) returns (AuthenticationResponse);
}

message AuthenticationRequest {
    optional string workspace_name = 1;
}

message AuthenticationResponse {
    optional string workspace_id = 1;
    string token = 2;
    ApiKeyType api_key_type = 3;
}

enum ApiKeyType {
    UNDECLARED = 0;
    USER = 1;
    SERVICE = 2;
}

service Observer {
    rpc Publish(PublishRequest) returns (PublishResponse);
}

message PublishRequest {
    repeated Record records = 1;
}

message PublishResponse {
    bool successful = 1;
    repeated RecordPublishJob jobs = 2;
    optional string message = 3;
}

message RecordPublishJob {
    string id = 1;
    string stream_key = 2;
}

enum LogType {
    UNDECLARED_LOG_TYPE = 0;
    EVENT = 1;
    RUNTIME = 2;
    INPUT = 3;
    OUTPUT = 4;
    FEEDBACK = 5;
    METADATA = 6;
}

enum Tier {
    UNDECLARED_TIER = 0;
    SYSTEM = 1;
    SUBSYSTEM = 2;
    COMPONENT = 3;
    SUBCOMPONENT = 4;
}

message Record {
    Tier tier = 1;

    string parent_id = 2;
    string id = 3;

    oneof record_data {
        EventRecord event = 4;
        RuntimeRecord runtime = 5;
        InputRecord input = 6;
        OutputRecord output = 7;
        FeedbackRecord feedback = 8;
        MetadataRecord metadata = 9;
    }
}

message EventRecord {
    string name = 1;
    optional google.protobuf.Value parameters = 2;
    optional string version = 3;
    optional string environment = 4;
}

message RuntimeRecord {
    float start_time = 1;
    float end_time = 2;
    optional string error_type = 3;
    optional string error_content = 4;
}

message InputRecord {
    string field_name = 1;
    google.protobuf.Value field_value = 2;
}

message OutputRecord {
    string field_name = 1;
    google.protobuf.Value field_value = 2;
}

message FeedbackRecord {
    string field_name = 1;
    google.protobuf.Value field_value = 2;
}

message MetadataRecord {
    string field_name = 1;
    string field_value = 2;
}
