syntax = "proto3";

package golem.component.v1;

import public "golem/common/plugin_installation_id.proto";
import public "golem/common/project_id.proto";
import public "golem/common/empty.proto";
import public "golem/component/component.proto";
import public "golem/component/component_type.proto";
import public "golem/component/dynamic_linked_instance.proto";
import public "golem/component/v1/component_error.proto";
import public "golem/component/component_id.proto";
import public "golem/component/component_constraints.proto";
import public "golem/component/component_files.proto";
import public "golem/component/plugin_installation.proto";

service ComponentService {
  rpc GetComponents (GetComponentsRequest) returns (GetComponentsResponse);
  rpc CreateComponent (stream CreateComponentRequest) returns (CreateComponentResponse);
  rpc DownloadComponent (DownloadComponentRequest) returns (stream DownloadComponentResponse);
  rpc GetComponentMetadataAllVersions (GetComponentRequest) returns (GetComponentMetadataAllVersionsResponse);
  rpc GetLatestComponentMetadata (GetLatestComponentRequest) returns (GetComponentMetadataResponse);
  rpc UpdateComponent (stream UpdateComponentRequest) returns (UpdateComponentResponse);
  rpc GetComponentMetadata(GetVersionedComponentRequest) returns (GetComponentMetadataResponse);
  rpc CreateComponentConstraints(CreateComponentConstraintsRequest) returns (CreateComponentConstraintsResponse);
  rpc DeleteComponentConstraint(DeleteComponentConstraintsRequest) returns (DeleteComponentConstraintsResponse);

  rpc GetInstalledPlugins (GetInstalledPluginsRequest) returns (GetInstalledPluginsResponse);
  rpc InstallPlugin (InstallPluginRequest) returns (InstallPluginResponse);
  rpc UpdateInstalledPlugin (UpdateInstalledPluginRequest) returns (UpdateInstalledPluginResponse);
  rpc UninstallPlugin (UninstallPluginRequest) returns (UninstallPluginResponse);
}

message CreateComponentConstraintsRequest {
  ComponentConstraints componentConstraints = 1;
}

message DeleteComponentConstraintsRequest {
  ComponentConstraints componentConstraints = 1;
}

message CreateComponentConstraintsResponse {
  oneof result {
    CreateComponentConstraintsSuccessResponse success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message DeleteComponentConstraintsResponse {
  oneof result {
    DeleteComponentConstraintsSuccessResponse success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message CreateComponentConstraintsSuccessResponse {
  ComponentConstraints components = 1;
}

message DeleteComponentConstraintsSuccessResponse {
  ComponentConstraints components = 1;
}

message GetComponentsRequest {
  golem.common.ProjectId projectId = 1;
  optional string componentName = 2;
}

message GetComponentsResponse {
  oneof result {
    GetComponentsSuccessResponse success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message GetComponentsSuccessResponse {
  repeated golem.component.Component components = 1;
}

message CreateComponentRequest {
  oneof data {
    CreateComponentRequestHeader header = 1;
    CreateComponentRequestChunk chunk = 2;
  }
}

message CreateComponentRequestHeader {
  golem.common.ProjectId projectId = 1;
  string componentName = 2;
  optional ComponentType componentType = 3;
  // All files need to be uploaded to the blob storage before providing them here
  repeated InitialComponentFile files = 4;
  map<string, golem.component.DynamicLinkedInstance> dynamic_linking = 5;
  map<string, string> env = 6;
}

message CreateComponentRequestChunk {
  bytes componentChunk = 1;
}

message CreateComponentResponse {
  oneof result {
    golem.component.Component success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message DownloadComponentRequest {
  golem.component.ComponentId componentId = 1;
  optional uint64 version = 2;
}

message DownloadComponentResponse {
  oneof result {
    bytes successChunk = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message GetComponentRequest {
  golem.component.ComponentId componentId = 1;
}

message GetVersionedComponentRequest {
  golem.component.ComponentId componentId = 1;
  uint64 version = 2;
}

message GetComponentMetadataAllVersionsResponse {
  oneof result {
    GetComponentSuccessResponse success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message GetComponentMetadataResponse {
  oneof result {
    GetComponentMetadataSuccessResponse success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message GetComponentMetadataSuccessResponse {
  optional golem.component.Component component = 1;
}

message GetComponentSuccessResponse {
  repeated golem.component.Component components = 1;
}

message GetLatestComponentRequest {
  golem.component.ComponentId componentId = 1;
}

message UpdateComponentRequest {
  oneof data {
    UpdateComponentRequestHeader header = 1;
    UpdateComponentRequestChunk chunk = 2;
  }
}

message UpdateComponentRequestHeader {
  golem.component.ComponentId componentId = 1;
  optional ComponentType componentType = 2;
  // Whether to update the files or not. If false, the files field will be ignored and file from the previous version will be used.
  bool updateFiles = 3;
  // All files need to be uploaded to the blob storage before providing them here
  repeated InitialComponentFile files = 4;
  map<string, golem.component.DynamicLinkedInstance> dynamic_linking = 5;
  map<string, string> env = 6;
}

message UpdateComponentRequestChunk {
  bytes componentChunk = 1;
}

message UpdateComponentResponse {
  oneof result {
    golem.component.Component success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message GetInstalledPluginsRequest {
  golem.component.ComponentId componentId = 1;
  optional uint64 version = 2;
}

message GetInstalledPluginsResponse {
  oneof result {
    GetInstalledPluginsSuccessResponse success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message GetInstalledPluginsSuccessResponse {
  repeated golem.component.PluginInstallation installations = 1;
}

message InstallPluginRequest {
  golem.component.ComponentId componentId = 1;
  string name = 2;
  string version = 3;
  int32 priority = 4;
  map<string, string> parameters = 5;
}

message InstallPluginResponse {
  oneof result {
    InstallPluginSuccessResponse success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message InstallPluginSuccessResponse {
  golem.component.PluginInstallation installation = 1;
}

message UpdateInstalledPluginRequest {
  golem.component.ComponentId componentId = 1;
  golem.common.PluginInstallationId installationId = 2;
  int32 updated_priority = 3;
  map<string, string> updated_parameters = 4;
}

message UpdateInstalledPluginResponse {
  oneof result {
    golem.common.Empty success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}

message UninstallPluginRequest {
  golem.component.ComponentId componentId = 1;
  golem.common.PluginInstallationId installationId = 2;
}

message UninstallPluginResponse {
  oneof result {
    golem.common.Empty success = 1;
    golem.component.v1.ComponentError error = 2;
  }
}
