syntax = "proto3";

import "gogo/protobuf/gogoproto/gogo.proto";
import "protobuf/types/service.proto";

package mesg.api;
option go_package = "api";

// This is the API to interact with the Services.
//
// This API is a [gRPC](https://grpc.io/) API.
//
// The source file of this API is hosted on [GitHub](https://github.com/mesg-foundation/engine/blob/master/protobuf/api/service.proto).
service Service {

  // Create a Service from a Service Definition.
  // It will return an unique identifier which is used to interact with the Service.
  rpc Create (CreateServiceRequest) returns (CreateServiceResponse) {}

  // Get returns a Service matching the criteria of the request.
  rpc Get(GetServiceRequest) returns (types.Service) {}

  // List returns services specified in a request.
  rpc List(ListServiceRequest) returns (ListServiceResponse) {}

  // Exists return if a service already exists.
  rpc Exists(ExistsServiceRequest) returns (ExistsServiceResponse) {}

  // Hash return the hash of a service
  rpc Hash(CreateServiceRequest) returns (HashServiceResponse) {}
}

// The request's data for the `Create` API.
message CreateServiceRequest {
  // Service's sid.
  string sid = 1;

  // Service's name.
  string name = 2;

  // Service's description.
  string description = 3;

  // Configurations related to the service
  types.Service.Configuration configuration = 4 [
    (gogoproto.nullable) = false
  ];

  // The list of tasks this service can execute.
  repeated types.Service.Task tasks = 5;

  // The list of events this service can emit.
  repeated types.Service.Event events = 6;

  // The container dependencies this service requires.
  repeated types.Service.Dependency dependencies = 7;

  // Service's repository url.
  string repository = 8;

  // The hash id of service's source code on IPFS.
  string source = 9;
}

// The response's data for the `Create` API.
message CreateServiceResponse {
  // The service's hash created.
  bytes hash = 1 [
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];
}

// The request's data for the `Get` API.
message GetServiceRequest {
  // The service's hash to fetch.
  bytes hash = 1 [
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];
}

// The request's data for the `List` API.
message ListServiceRequest {}

// The response's data for the `List` API.
message ListServiceResponse {
  // List of services that match the request's filters.
  repeated types.Service services = 1;
}

// The request's data for the `List` API.
message ExistsServiceRequest {
  // The service's hash of the existing service. This hash is nil if exists is fals.
  bytes hash = 1 [
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];
}

// The response's data for the `Exists` API.
message ExistsServiceResponse {
  // True if a service already exists, false otherwise.
  bool exists = 1;
}

// The request's data for the `Hash` API.
message HashServiceResponse {
  // Hash of the service calculated.
  bytes hash = 1 [
    (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash",
    (gogoproto.nullable) = false
  ];
}
