// Proposed contract, version 1. Status: proposal for review, not confirmed design.
//
// The model APIs other systems call. A prediction reads canonical inputs at a write number and is recorded as a
// ModelRun; the caller stores the outputs as computed records.
// Callers: farm (ListModels for the Organization Dashboard's catalog; Predict for on-demand predictions behind
// farm.models.use and the model's entitlement feature; req 62, 1002.24, 1006.25).
// Deadline: ListModels 2 s, Predict 30 s.
// The callers listed are authentication only (decided 2026-11-11): each RPC below names who may call it and what
// it sees, and refuses anyone else with PERMISSION_DENIED.
// x-moonitoring-callers: farm
// x-moonitoring-requirements: 62, 1002.24, 1006.25
syntax = "proto3";

package moonitoring.ai_model_platform.models.v1;

service ModelsService {
  // The models with a deployed version, with the feature that gates each one.
  // Callers: farm only. Sees: the catalog of deployed models, no farm data.
  rpc ListModels(ListModelsRequest) returns (ListModelsResponse);
  // Predictions for animals of one farm with the deployed version of a model.
  // Callers: farm only, after it checked farm.models.use and the model's entitlement. Sees: the predictions for
  // the farm and the animals of the request.
  rpc Predict(PredictRequest) returns (PredictResponse);
}

message ListModelsRequest {}

message ListModelsResponse {
  repeated Model models = 1;
}

message Model {
  string id = 1;
  string name = 2;
  string description = 3;
  // e.g. farm.models.mastitis.
  string feature = 4;
  OutputKind output_kind = 5;
  string output_observation_type_id = 6;
  string output_event_type = 7;
  string deployed_version = 8;
}

enum OutputKind {
  OUTPUT_KIND_UNSPECIFIED = 0;
  OUTPUT_KIND_OBSERVATION = 1;
  OUTPUT_KIND_EVENT = 2;
}

message PredictRequest {
  string request_id = 1;
  string model_name = 2;
  string farm_id = 3;
  repeated string animal_ids = 4;
  // The write number to read inputs at; 0 means the watermark.
  int64 data_seq = 5;
}

message PredictResponse {
  // The ModelRun recorded for this prediction.
  string model_run_id = 1;
  string model_version_id = 2;
  // The OriginVersion that identifies the model and its version as a ComputedSourceOrigin.
  string origin_version_id = 3;
  repeated Prediction predictions = 4;
}

message Prediction {
  string animal_id = 1;
  // ObservationValue as JSON.
  string value_json = 2;
  // Exact input revisions, for the derivation.
  repeated string input_revision_ids = 3;
}
