syntax = "proto3";

package qwilprobe;

/**
 * An interface for a microservice that serves probe data to qwilfish.
 */
service Qwilprobe {
    rpc GetProbeInfo(ProbeInfoRequest) returns (ProbeInfoResponse) {}
    rpc GetProbeIsReady(ProbeIsReadyRequest) returns (ProbeIsReadyResponse) {}
    rpc GetProbeData(ProbeDataRequest) returns (ProbeDataResponse) {}
    rpc Terminate(ProbeTerminateRequest) returns (ProbeTerminateResponse) {}
}

/**
 * Request some info about a probe.
 */
message ProbeInfoRequest {}

/**
 * Provide some basic info about the service.
 */
message ProbeInfoResponse {

    /**
     * Required. An identifier for the probe which needs to be unique for any
     * session in which the probe is being used.
     */
    string uid = 1;

    /**
     * Required. A model for the data served by the probe.
     */
    ProbeDataModel data_model = 2;

    /**
     * Optional. A description of the probe. Optional.
     */
    string description = 3;
}

/**
 * The data model is just one or more columns in a database
 * (think SQLite table).
 */
message ProbeDataModel {
    repeated ProbeDataColumn columns = 1;
}

/**
 * Respond with metadata about a column in the data model.
 */
message ProbeDataColumn {

    /**
     * Required. Name of the column that will contain the data.
     */
    string column_name = 1;

    /**
     * Required. Type of data being stored in the column (again, think SQLite).
     */
    ProbeDataType column_type = 3;

    /**
     * Optional. A description for the data being stored in this column.
     */
    string column_description = 2;
}

/**
 * Three types supported so far. Maps one-to-one with SQLite datatypes.
 */
enum ProbeDataType {
    INTEGER = 0;
    REAL = 1;
    STRING = 2;
}

/**
 * Check if a probe is ready.
 */
message ProbeIsReadyRequest {}

/**
 * Respond with ready status.
 */
message ProbeIsReadyResponse {

    /**
     * Set to false if probe is not ready to serve data. E.g. it might be
     * waiting for a process to (re-)start.
     */
    bool is_ready = 1;
}

/**
 * Request for the actual probe data that qwilfish will consume.
 */
message ProbeDataRequest {}

/**
 * Respond with the actual probe data.
 */
message ProbeDataResponse {

    /**
     * One or more probe datapoints.
     */
    repeated ProbeDatapoint probe_data = 1;
}

/**
 * Wrapper type for a datapoint. A key-value pair where the key is the
 * corresponding column name in the probe's data model.
 */
message ProbeDatapoint {

    /**
     * Key. Must be one of the column names that ProbeInfoResponse presents
     * in its data model field.
     */
    string key = 1;

    /**
     * Value. The datapoint can have three possible types. Must match the
     * column type that ProbeInfoResponse presents in its data model field.
     */
    oneof value {
        int64 intval = 2;
        double realval = 3;
        string stringval = 4;
    }
}

/**
 * Request to terminate the service.
 */
message ProbeTerminateRequest {}

/**
 * Response just before the service is terminated.
 */
message ProbeTerminateResponse {}
