/*
Proto contract for the VectorCompose worker.

Version     Date            Author      Comment
V1.0.0      16-04-2026      MiAl        Initial version
*/

syntax = "proto3";

import "Interfaces/google/api/annotations.proto";
import "google/protobuf/empty.proto";

package vectorcomposeworker;

option csharp_namespace = "Bergstein.Digi.Shared.Interfaces.PrintManager.VectorCompose.Worker.Protos.V2";

// Service for Vector Compose Worker instance.
service VectorComposeWorker {
  /*
  Endpoint for loading a VectorCompose SVG job into the worker browser session.

  Returns on a success:
  - the current worker state and the discovered worker info for the loaded job

  Returns on a failure:
  - CANCELLED (1) status when you abort the call
  - INTERNAL (13) status when something went wrong on the server (please contact your administrator in this case)
  */
  rpc LoadJob (LoadJobRequest) returns (LoadJobReply) {
    option (google.api.http) = {
      post: "/vectorcomposeworker_module/v1/job/load"
      body: "*"
    };
  }

  /*
  Endpoint for fetching the current job info for the loaded VectorCompose job.

  Returns on a success:
  - the current job info

  Returns on a failure:
  - CANCELLED (1) status when you abort the call
  - INTERNAL (13) status when something went wrong on the server (please contact your administrator in this case)
  */
  rpc GetJobInfo (google.protobuf.Empty) returns (JobInfo) {
    option (google.api.http) = {
      get: "/vectorcomposeworker_module/v1/job/info"
    };
  }

  /*
  Endpoint for exporting the currently loaded VectorCompose job to the worker output folder.

  Returns on a success:
  - the saved file path

  Returns on a failure:
  - CANCELLED (1) status when you abort the call
  - INTERNAL (13) status when something went wrong on the server (please contact your administrator in this case)
  */
  rpc SaveJob (SaveJobRequest) returns (SaveJobReply) {
    option (google.api.http) = {
      post: "/vectorcomposeworker_module/v1/job/save"
      body: "*"
    };
  }

  /*
  Endpoint for fetching the current available plugin actions for the loaded VectorComposeJob.

  Returns on a success:
  - the a list of Plugin Actions

  Returns on a failure:
  - CANCELLED (1) status when you abort the call
  - INTERNAL (13) status when something went wrong on the server (please contact your administrator in this case)
  */
  rpc GetPluginActions (GetPluginActionsRequest) returns (GetPluginActionsReply) {
    option (google.api.http) = {
      get: "/vectorcomposeworker_module/v1/plugin/actions"
    };
  }

  /*
  Endpoint for setting/activating plugin actions for the loaded VectorComposeJob.

  Returns on a success:
  - the a list of success and/or failed Plugin Action results

  Returns on a failure:
  - CANCELLED (1) status when you abort the call
  - INTERNAL (13) status when something went wrong on the server (please contact your administrator in this case)
  */
  rpc SetPluginActions (SetPluginActionsRequest) returns (SetPluginActionsReply) {
    option (google.api.http) = {
      post: "/vectorcomposeworker_module/v1/plugin/actions"
      body: "*"
    };
  }

  /*
  Endpoint for fetching the current state of the loaded VectorComposeJob.

  Returns on a success:
  - the current state of the job

  Returns on a failure:
  - CANCELLED (1) status when you abort the call
  - INTERNAL (13) status when something went wrong on the server (please contact your administrator in this case)
  */
  rpc GetState (google.protobuf.Empty) returns (GetStateReply) {
    option (google.api.http) = {
      get: "/vectorcomposeworker_module/v1/state"
    };
  }

  /*
  Endpoint for fetching the stored logs of the loaded VectorComposeJob.

  Returns on a success:
  - the a list of log entries

  Returns on a failure:
  - CANCELLED (1) status when you abort the call
  - INTERNAL (13) status when something went wrong on the server (please contact your administrator in this case)
  */
  rpc GetLogs (GetLogsRequest) returns (GetLogsReply) {
    option (google.api.http) = {
      get: "/vectorcomposeworker_module/v1/logs"
    };
  }
}

message LoadJobRequest {
  string file_path = 1;
}

message LoadJobReply {
  State state = 1;
  string loaded_file_path = 3;
}

message SaveJobRequest {
  string output_file_name = 1;
}

message SaveJobReply {
  string output_file_path = 1;
}

message JobInfo {
  SvgInfo svg = 1;
  uint32 plugin_count = 2;
  repeated string plugin_names = 3;
}

message SvgInfo {
  string id = 1;
  string width = 2;
  string height = 3;
}

message GetPluginActionsRequest {
    // Future: filter fields
}

message GetPluginActionsReply {
    repeated PluginActionDefinitions plugin_action_definitions = 1;
}

message PluginActionDefinitions {
    string plugin_name = 1;
    string domain = 2;
  repeated PluginActionDefinition definitions = 3;
}

message PluginActionDefinition {
    // The action name
    string action_name = 1;
    // The return type of this action
    string return_type = 2;
    // The list of arguments of this action
  repeated PluginActionArgument arguments = 3;
}

message PluginActionArgument {
    // The name of the action argument
    string name = 1;
    // The type of the value
    string type = 2;
    // This action argument is optional
    bool optional = 3;
}

message SetPluginActionsRequest {
    repeated PluginActionRequest plugin_actions = 1;
}

message SetPluginActionsReply {
    repeated PluginActionReply results = 1;
}

message PluginActionRequest {
    string plugin_name = 1;
    repeated Parameter parameters = 2;
}

message PluginActionReply {
    string plugin_name = 1;
    string action = 2;
    repeated Parameter parameters = 3;
    string result = 4;
    bool success = 5;
}

message Parameter {
    string name = 1;
    string value = 2;
}

message GetStateReply {
    State state = 1;
}

enum State {
    STATE_UNKNOWN = 0;
    STATE_EMPTY = 1;
    STATE_LOADED = 2;
    STATE_ERROR = 3;
}

message GetLogsRequest {
    // Future: filter fields
}

message GetLogsReply {
    repeated LogEntry log_entries = 1;
}

message LogEntry {
    string timestamp = 1;
    ConsoleType type = 2;
    string message = 3;
  repeated LogArgument arguments = 4;
}

message LogArgument {
  string name = 1;
  string type = 2;
  string value = 3;
}

enum ConsoleType {
    CONSOLETYPE_UNKNOWN = 0;
    CONSOLETYPE_LOG = 1;
    CONSOLETYPE_DEBUG = 2;
    CONSOLETYPE_INFO = 3;
    CONSOLETYPE_ERROR = 4;
    CONSOLETYPE_WARNING = 5;
    CONSOLETYPE_DIR = 6;
    CONSOLETYPE_DIRXML = 7;
    CONSOLETYPE_TABLE = 8;
    CONSOLETYPE_TRACE = 9;
    CONSOLETYPE_CLEAR = 10;
    CONSOLETYPE_STARTGROUP = 11;
    CONSOLETYPE_STARTGROUPCOLLAPSED = 12;
    CONSOLETYPE_ENDGROUP = 13;
    CONSOLETYPE_ASSERT = 14;
    CONSOLETYPE_PROFILE = 15;
    CONSOLETYPE_PROFILEEND = 16;
    CONSOLETYPE_COUNT = 17;
    CONSOLETYPE_TIMEEND = 18;
    CONSOLETYPE_VERBOSE = 19;
    CONSOLETYPE_TIMESTAMP = 20;
}
