syntax = "proto3";

package com.wixpress.appservice.api;

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

// A component that describes a Function
// Design is highly influenced by business schema api
message Function {
  reserved 1; // spi_identifier
  // Name of the function. Optional to define
  reserved 2; // display_name
  // Description of the function. Optional to define
  reserved 3; // display_description
  // Function method definitions
  repeated Definition definitions = 4 [(.wix.api.maxSize) = 100];
  reserved 5; // multiple_instances_allowed
  // Function configuration
  Configuration configuration = 6;
  // Function description
  Description description = 7;

  // Function definition
  // IMPORTANT! Initial product will support only single function definition
  message Definition {
    option (.wix.api.unique) = {field: "method"};

    // Method
    string method = 1 [(wix.api.maxLength) = 255];
    reserved 2; // input_schema
    reserved 3; // output_schema
    reserved 4; // output_ui
    // Function input.
    Input input = 6;
    // Function output.
    Output output = 7;
    // We do not know the component trigger key on creation of function component
    // Because the same function component can be implemented multiple times
    reserved 5; // trigger_key
    .google.protobuf.StringValue trigger_id = 8 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
  }

  message Input {
    // Schema definition: https://json-schema.org/draft/2020-12/schema
    // Protobuf does not support `$` variables -- cannot define the json-schema in protobuf
    .google.protobuf.Struct schema = 1;
    // UI definition
    .google.protobuf.Struct ui = 2;
    // Input display description
    .google.protobuf.StringValue display_description = 3 [(.wix.api.maxLength) = 100, (.wix.api.translatable) = {
      type: LONG_TEXT
      name: "Input node display description"
    }];
    // Builder SPI
    BuilderSpi builder_spi = 4;

    message BuilderSpi {
      // SPI url called from Function Builder
      .google.protobuf.StringValue base_uri = 1 [(.wix.spi.base_uri) = true, (.wix.api.maxLength) = 1000];
      // Whether SPI supports appending Input Schema dynamically
      .google.protobuf.BoolValue dynamic_schema_fetching_enabled = 2;
    }
  }

  message Output {
    // Schema definition: https://json-schema.org/draft/2020-12/schema
    // Protobuf does not support `$` variables -- cannot define the json-schema in protobuf
    .google.protobuf.Struct schema = 1;
    // UI definition
    .google.protobuf.Struct ui = 2;
    // Defined state
    State defined = 3;
    // Empty state
    State empty = 4;

    message State {
      reserved 1; // title
      // State description
      .google.protobuf.StringValue description = 2 [(wix.api.maxLength) = 100, (.wix.api.translatable) = {
        type: SHORT_TEXT
        name: "Output empty and defined state description"
      }];
    }
  }

  message Description {
    .google.protobuf.StringValue about_description = 1 [(wix.api.maxLength) = 600, (.wix.api.translatable) = {
      type: LONG_TEXT
      name: "About description"
    }];
    // Description of how it works
    .google.protobuf.StringValue how_it_works_description = 2 [(wix.api.maxLength) = 1000, (.wix.api.translatable) = {
      type: RICH_CONTENT_EDITOR
      name: "How it works description"
    }];
    // Description of the outcome
    .google.protobuf.StringValue outcome_description = 3 [(wix.api.maxLength) = 600, (.wix.api.translatable) = {
      type: RICH_CONTENT_EDITOR
      name: "Outcome description"
    }];
    // Representative image
    .wix.common.Image representative_image = 4;
    // Title of the builderless function template selection modal
    .google.protobuf.StringValue builderless_template_selection_modal_title = 5 [(.wix.api.maxLength) = 50, (.wix.api.translatable) = {
      type: SHORT_TEXT
      name: "Builderless function template selection modal title"
    }];
    // Subtitle of the builderless function template selection modal
    .google.protobuf.StringValue builderless_template_selection_modal_subtitle = 6 [(.wix.api.maxLength) = 200, (.wix.api.translatable) = {
      type: SHORT_TEXT
      name: "Builderless function template selection modal subtitle"
    }];
  }

  message Configuration {
    // Function can be implemented multiple times on single site
    .google.protobuf.BoolValue multiple_instances_allowed = 1;
    // Spi configuration
    Spi spi = 2;
    // Do not include the function in the functions catalog in the BM
    .google.protobuf.BoolValue hide_from_functions_catalog = 3 [(.wix.api.field_exposure) = INTERNAL];
    // The custom initial preset to use when building a function from scratch
    CustomInitialPreset custom_initial_preset = 4;
    // Do not include the function in the create with AI flow
    .google.protobuf.BoolValue hide_from_create_with_ai = 5 [(.wix.api.field_exposure) = INTERNAL];

    message Spi {
      // SPI fqdn
      .google.protobuf.StringValue fqdn = 1 [(wix.api.maxLength) = 200];
      // Configuration based on dev center SPI component configuration
      // Schema definition: https://json-schema.org/draft/2020-12/schema
      .google.protobuf.Struct schema = 2;
      // UI definition
      .google.protobuf.Struct ui = 3;
      // SPI configuration modal title
      reserved 4; // title
      // SPI configuration modal description
      reserved 5; // description
    }

    message CustomInitialPreset {
      // Custom initial function template extension id
      .google.protobuf.StringValue function_template_extension_id = 1 [(.wix.api.format) = GUID, (.wix.api.referenced_entity) = "wix.devcenter.components.v1.component"];
      // Indicates whether the custom initial preset with a custom function template is enabled; if false, the blank function template is used
      .google.protobuf.BoolValue enabled = 2;
    }
  }
}
