// This proto file was generated from units-service-api.yml.
// Care should be taken while both files exist to maintain backwards compatibility with the Conjure generated code.

syntax = "proto3";

package nominal.units.v1;

import "google/api/annotations.proto";
import "nominal/conjure/v1/compat.proto";
import "nominal/gen/v1/alias.proto";
import "nominal/gen/v1/error.proto";

option java_multiple_files = true;
option java_package = "io.nominal.units.v1";

message GetAllUnitsResponse {
  map<string, GetUnitsResponseUnitsByPropertyWrapper> units_by_property = 1 [
    (nominal.gen.v1.alias) = {key_java_name: "io.nominal.scout.units.api.UnitProperty"},
    (nominal.conjure.v1.conjure_field_compat) = {map_value_wrapper: true}
  ];

  message GetUnitsResponseUnitsByPropertyWrapper {
    repeated Unit value = 1;
  }
}

message Unit {
  optional string name = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.scout.units.api.UnitName"}];

  string symbol = 2 [(nominal.gen.v1.alias) = {java_name: "io.nominal.scout.units.api.UnitSymbol"}];

  // Empty if no property is available. If two units measure different properties, it is not possible to
  // convert between them.
  optional string property = 3 [(nominal.gen.v1.alias) = {java_name: "io.nominal.scout.units.api.UnitProperty"}];

  // The physical dimensions in terms of the base units of the system. It is only possible to convert units if
  // they have the same dimension. Empty if the unit is a base unit.
  optional UnitDimension dimension = 4;

  string system = 5 [(nominal.gen.v1.alias) = {java_name: "io.nominal.scout.units.api.UnitSystem"}];
}

// The fundamental base dimensions and their exponents, whose product compose a unit.
message UnitDimension {
  map<string, int32> base_dimensions = 1;
}

message GetAllUnitsRequest {}

message GetUnitRequest {
  string unit = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.scout.units.api.UnitSymbol"}];
}

message GetUnitResponse {
  optional Unit unit = 1;
}

message GetBatchUnitsRequest {
  repeated string units = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.scout.units.api.UnitSymbol"}];
}

message GetBatchUnitsResponse {
  map<string, Unit> responses = 1 [(nominal.gen.v1.alias) = {key_java_name: "io.nominal.scout.units.api.UnitSymbol"}];
}

message GetCommensurableUnitsRequest {
  string unit = 1 [(nominal.gen.v1.alias) = {java_name: "io.nominal.scout.units.api.UnitSymbol"}];
}

message GetCommensurableUnitsResponse {
  repeated Unit units = 1;
}

// buf:lint:ignore ENUM_ZERO_VALUE_SUFFIX
enum ScoutError {
  SCOUT_ERROR_CANNOT_DESERIALIZE_SEARCH_TOKEN = 0 [(nominal.gen.v1.error) = {
    code: "INVALID_ARGUMENT"
    message: "CannotDeserializeSearchToken"
  }];
  // The start time of the provided Range is greater than its end time.
  SCOUT_ERROR_INVALID_RANGE = 1 [(nominal.gen.v1.error) = {
    code: "INVALID_ARGUMENT"
    message: "The start time of the provided Range is greater than its end time."
  }];
  SCOUT_ERROR_REQUESTED_PAGE_SIZE_TOO_LARGE = 2 [(nominal.gen.v1.error) = {
    code: "INVALID_ARGUMENT"
    message: "RequestedPageSizeTooLarge"
  }];
}

// The Units Service serves as a comprehensive catalog of the units of measurement supported by scout. Units, by
// default, follow the UCUM convention for representation.
service UnitsService {
  // Returns all known units, grouped by the physical property they measure.
  rpc GetAllUnits(GetAllUnitsRequest) returns (GetAllUnitsResponse) {
    option (google.api.http) = {get: "/units/v1/units"};
  }
  // Returns information for a unit symbol if available. Returns as empty if the provided symbol cannot be parsed.
  rpc GetUnit(GetUnitRequest) returns (GetUnitResponse) {
    option (google.api.http) = {
      post: "/units/v1/units/get-unit"
      response_body: "unit"
      body: "unit"
    };
  }
  // Returns information for the unit symbols if available. If the provided symbol cannot be parsed, it will be
  // omitted from the map.
  rpc GetBatchUnits(GetBatchUnitsRequest) returns (GetBatchUnitsResponse) {
    option (google.api.http) = {
      post: "/units/v1/units/get-batch-units"
      response_body: "responses"
      body: "units"
    };
  }
  // Returns the set of cataloged units that can be converted to and from the given unit.
  // No commensurable units does not imply the unit is invalid. Use /get-unit to check for validity.
  rpc GetCommensurableUnits(GetCommensurableUnitsRequest) returns (GetCommensurableUnitsResponse) {
    option (google.api.http) = {
      post: "/units/v1/units/commensurable-units"
      response_body: "units"
      body: "unit"
    };
  }
}
