syntax = "proto3";

import "google/protobuf/struct.proto";
import "google/protobuf/wrappers.proto";
import "wix/spi/definitions.proto";
import "wix/api/annotations.proto";
import "wix/api/validations.proto";
import "wix/common/media.proto";

package com.wixpress.appservice.api.upstream.com.wixpress.esb.spi.action.v1;

message ActionProviderSPIConfig {
  reserved 1;
  // URL to action provider service for this action
  string base_uri = 2 [(.wix.spi.base_uri) = true];
  // Action service plugin configuration
  ActionSPIConfig action_config = 3;
}

message ActionSPIConfig {
  // Identifier for this action - human-readable action key - unique per app def ID
  string action_key = 1 [(.wix.api.minLength) = 5, (.wix.api.maxLength) = 50];

  // The action expects the following input
  // The schema is described according to the JSON Schema standard: https://json-schema.org/
  //
  // Example - Add Label to Contact Action input schema:
  // {
  // "$schema": "https://json-schema.org/draft/2020-12/schema",
  // "type": "object",
  // "title": "Add label to contact input schema",
  // "description": "The schema of the JSON that is sent when invoking this add label to contact action",
  // "default": {},
  // "examples": [
  // {
  // "contactId": "a647eb32-c5f4-11ec-9d64-0242ac120002",
  // "labelId": "1e8b5e5e-dba2-11ec-9d64-0242ac120002"
  // }
  // ],
  // "required": [
  // "contactId",
  // "labelId"
  // ],
  // "properties": {
  // "contactId": {
  // "$id": "#/properties/contactId",
  // "type": "string",
  // "format": "uuid",
  // "title": "Contact Id",
  // "description": "The ID of the contact to apply the label to",
  // "default": "",
  // "identityType": "contact" // can be contact/visitor/user, limited to 1 type per identity.
  // },
  // "labelId": {
  // "$id": "#/properties/labelId",
  // "type": "string",
  // "format": "uuid",
  // "title": "Label Id",
  // "description": "The ID of the label to apply",
  // "default": "",
  // }
  // }
  // }
  //
  google.protobuf.Struct input_schema = 3;

  // The output of the action, which will be added to the payload after execution.
  // The schema is described according to the JSON Schema standard: https://json-schema.org/
  //
  // Example - Output of create task action
  // {
  // "$schema": "https://json-schema.org/draft/2020-12/schema",
  // "type": "object",
  // "title": "Create task action schema",
  // "description": "The schema of the JSON that is sent when invoking this create task action",
  // "default": {},
  // "examples": [
  // {
  // "taskId": "a647eb32-c5f4-11ec-9d64-0242ac120002",
  // }
  // ],
  // "required": [
  // "taskId"
  // ],
  // "properties": {
  // "taskId": {
  // "$id": "#/properties/taskId",
  // "type": "string",
  // "format": "uuid",
  // "title": "Contact Id",
  // "description": "The ID of the task created",
  // "default": "",
  // }
  // }
  // }
  //
  google.protobuf.Struct output_schema = 4;

  // Actions display name - human-readable field. Ex. - "Send SMS"
  google.protobuf.StringValue display_name = 7 [(.wix.api.minLength) = 5, (.wix.api.maxLength) = 80];

  google.protobuf.StringValue description = 8;

  // Specifies which optional methods were implemented
  ImplementedMethods implemented_methods = 5;
  // Indicates whether we should wait for the action to complete before executing the next actions or finish and
  // expect a callback in the `actionCompleted` method.
  ExecutionType execution_type = 2 [deprecated = true, (.wix.api.field_deprecated) = {target_removal_date: "2025-03-10"}];

  Metadata metadata = 6 [(.wix.api.field_exposure) = INTERNAL];

  // Chosen interface for action.
  InterfaceConfiguration interface_configuration = 9;

  // Icon representing the action in the UI
  wix.common.Image icon = 10;

  // The action configuration source information
  Source source = 11 [(.wix.api.field_exposure) = INTERNAL];

  // action id
  google.protobuf.StringValue id = 12 [(.wix.api.format) = GUID];

  //disable-flynt renamed-field-breaking-change
  message ImplementedMethods {
    // Implements ValidateConfiguration
    bool validate_configuration = 1;
    // Implements DuplicateInputMapping
    bool duplicate_input_mapping = 2;
    // Implements GenerateApplicationAutomationInputMapping
    bool generate_application_automation_input_mapping = 3;
    // Implements GetQuotaInfo
    bool get_quota_info = 4;
    // Implements OnBeforeSave
    bool on_before_save = 5;
    // Implements OnReset
    bool on_reset = 6;
    reserved 7;
    // implements generateActionInputMappingFromTemplate
    bool generate_action_input_mapping_from_template = 8;
    // implements OnRemove
    bool on_remove = 9;
    // Implements GetDynamicInputSchema
    bool get_dynamic_input_schema = 10;
    // Implements MergeInputMappings
    bool merge_input_mappings = 11;
    // Implements GetDynamicOutputSchema
    bool get_dynamic_output_schema = 12;
    // Implements GenerateInputMappingFromIntent
    //flynt-disable renamed-field-breaking-change
    bool generate_input_mapping_from_intent = 13;
  }

  enum ExecutionType {
    UNKNOWN_EXECUTION_TYPE = 0;
    SYNC = 1;
    ASYNC = 2;
  }

  message Metadata {
    // Show action only to advanced mode users (Wix staff)
    bool hidden = 1;
  }

  message InterfaceConfiguration {
    // Type of chosen interface.
    Type type = 1;
    oneof options {
      option (.wix.api.aligned_with_enum).field = "type";
      WidgetComponentOptions widget_component_options = 2 [(.wix.api.field_exposure) = INTERNAL];
      GenericOptions generic_options = 3;
    }

    enum Type {
      UNKNOWN_TYPE = 0;
      WIDGET_COMPONENT = 1 [(.wix.api.enum_exposure) = INTERNAL];
      GENERIC = 2;
    }

    message WidgetComponentOptions {
      // Name of provided component
      string component_name = 1 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 80];
    }

    message GenericOptions {
      // UI schema
      google.protobuf.Struct ui_schema = 1;
    }
  }

  message Source {
    enum SourceType {
      UNKNOWN_SOURCE_TYPE = 0 [(.wix.api.enum_maturity) = NOT_IMPLEMENTED];
      DEV_CENTER = 1;  // The input/output schemas are constructed by developers in Dev Center using the self-service flow
      WIX_API = 2; // The input/output schemas are derived from an existing Wix API through the API-to-Action feature
      INTEGRATION = 3; // The action invokes external API methods based on configuration
    }
    // the source type
    SourceType type = 1;

    message WixApiOptions {
      // Service entity fqdn
      string service_entity_fqdn = 1 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 100];
      // The service providing the API
      string service_name = 2 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 200];
      // The method name
      string method_name = 3 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 200];
    }

    message IntegrationOptions {
      enum IntegrationType {
        UNKNOWN_INTEGRATION_TYPE = 0 [(.wix.api.enum_maturity) = NOT_IMPLEMENTED];
        WIX_API = 1; // Integration with Wix API methods
      }
      // The integration type
      IntegrationType integration_type = 1;

    }

    // Additional source information based on type
    oneof options {
      option (.wix.api.aligned_with_enum).field = "type";
      // Wix API options
      WixApiOptions wix_api_options = 2;
      // Integration options
      IntegrationOptions integration_options = 3;
    }
  }

}
