syntax = "proto3";

package wix.devcenter.apps.components.v1;

import "com/wixpress/appservice/api/components_catalog_type.proto";
import "google/protobuf/wrappers.proto";
import "wix/api/validations.proto";
import "wix/api/annotations.proto";
import "wix/api/entity.proto";
import "wix/common/domainevents/domainevents.proto";
import "google/protobuf/empty.proto";
import "wix/api/subscription.proto";
import "wix/coreservices/businessschema/v1/common.proto";
import "google/api/annotations.proto";
import "wix/api/permissions.proto";
import "components_catalog_data.proto";
import "wix/devcenter/apps/permissions/v1/app_permission.proto";


service ComponentsCatalogService {
  option (.wix.api.service_maturity) = BETA;
  option (.wix.api.service_exposure) = PUBLIC;
  option (wix.api.service_entity).message = "wix.devcenter.apps.components.v1.ComponentTypeData";

  // Returns metadata about a component type
  //flynt-disable http-mapping-breaking-change
  rpc GetComponentTypeData (GetComponentTypeDataRequest) returns (GetComponentTypeDataResponse) {
    option (wix.api.exposure) = INTERNAL;
    option (.wix.api.permission) = {
      name: "DEV_CENTER.READ_COMPONENTS_CATALOG"
      type: MANUAL
    };
  }

  // Returns metadata about component types
  //flynt-disable http-mapping-breaking-change
  rpc GetComponentTypesData (GetComponentTypesDataRequest) returns (GetComponentTypesDataResponse) {
    option (wix.api.exposure) = INTERNAL;
    option (.wix.api.permission) = {
      name: "DEV_CENTER.READ_COMPONENTS_CATALOG"
      type: MANUAL
    };
  }

  // Returns metadata about component types
  rpc GetComponentTypesDisplayData (GetComponentTypesDisplayDataRequest) returns (GetComponentTypesDisplayDataResponse) {
    option (google.api.http).get = "/v1/components-catalog";
    option (wix.api.exposure) = PUBLIC;
    option (.wix.api.permission) = {
      name: "DEV_CENTER.READ_COMPONENTS_CATALOG"
      type: MANUAL
    };
  }

  // Updates the metadata of a component
  //flynt-disable http-mapping-breaking-change
  rpc UpdateComponentTypesData (UpdateComponentTypesDataRequest) returns (UpdateComponentTypesDataResponse) {
    option (wix.api.exposure) = PRIVATE;
    option (.wix.api.permission) = {
      name: "DEV_CENTER.WRITE_COMPONENTS_CATALOG"
      type: MANUAL
    };
  }

  // Consumes business schema domain events to update the components catalog
  rpc ConsumeSchemaChangedEvent (wix.common.domainevents.DomainEvent) returns (google.protobuf.Empty) {
    option (wix.api.exposure) = PRIVATE;
    option (wix.api.subscription) = {
      entity: "wix.coreservices.businessschema.v1.Entity",
    };
  }

}

message GetComponentTypeDataRequest {
  com.wixpress.appservice.api.ComponentType component_type = 1; // The component type to get data on
}

message GetComponentTypeDataResponse {
  ComponentTypeData component_type_data = 1; // The data about the component type
}

message GetComponentTypesDataRequest {}

message GetComponentTypesDataResponse {
  repeated ComponentTypeData component_types_data = 1; // The data about the component types
}

message GetComponentTypesDisplayDataRequest {}

message GetComponentTypesDisplayDataResponse {
  repeated ComponentTypeDisplayData component_types_display_data = 1; // The data about the component types
}

message UpdateComponentTypesDataRequest {
  map<string, DevCenterComponentTypeData> component_types_data_map = 1 [(.wix.api.maxSize) = 200]; // Map from component type name to the dev center data
}

message UpdateComponentTypesDataResponse {
  repeated ComponentTypeData component_type_data = 1; // The data about the component type
}

message ComponentTypeData {
// flynt-disable missing-extensible
  option (.wix.api.entity) = {
    fqdn: "wix.devcenter.v1.component_type_data"
    segment: USERS
  };
  string type = 1 [(.wix.api.maxLength) = 128]; // Component type
  DevCenterComponentTypeData dev_center_component_type_data = 2; // Data defined in components catalog
  BusinessSchemaComponentTypeData business_schema_component_type_data = 3; // Data defined in protos
}

message DevCenterComponentTypeData {
  string display_name = 1 [(.wix.api.maxLength) = 64]; // Name to be displayed in dev center
  bool requires_approval = 2; // If the component requires approval of dev relations team
  repeated string labels = 3 [(.wix.api.maxSize) = 32, (.wix.api.maxLength) = 64]; // Labels of components, as shown in dev center
  Attributes attributes = 4; // Attributes for validation
  google.protobuf.StringValue validation_provider = 5 [(.wix.api.format) = GUID]; // Component validation provider - called during create / update
  google.protobuf.StringValue dynamic_translations_provider = 6 [(.wix.api.format) = GUID]; // Additional translation keys providers
  google.protobuf.StringValue ownership_tag = 7 [(.wix.api.maxLength) = 64]; // Ownership tag of the component owner
  google.protobuf.StringValue component_reference_data_provider = 8 [(.wix.api.format) = GUID]; // ComponentReferenceData provider
  ComponentExample component_example = 9; // A pointer to an example component
  repeated google.protobuf.StringValue validation_providers = 10 [(.wix.api.maxSize) = 100, (.wix.api.format) = GUID]; // List of component validation providers - called during create / update
  google.protobuf.StringValue enricher_provider = 11 [(.wix.api.format) = GUID]; // Component enricher provider - called during create / update
  repeated wix.devcenter.apps.permissions.v1.Permission required_permissions = 12 [(wix.api.maxSize) = 1]; // permissions required to create a component of this type, currently only one permission is supported
}

message ComponentExample {
  string app_id = 1 [(.wix.api.format) = GUID]; // The app id of the example component
  string component_id = 2 [(.wix.api.format) = GUID]; //The component id of the example component
}

message BusinessSchemaComponentTypeData {
  google.protobuf.StringValue description = 1 [(.wix.api.maxLength) = 512]; // Description of the component, as shown in dev center
  wix.coreservices.businessschema.v1.Exposure exposure = 2; // Exposure of the component in Dev Center. Public - open to all, Internal - open to Wix employees, Private - open to none
  google.protobuf.StringValue learn_more_link = 3 [(.wix.api.format) = WEB_URL]; // Learn more link, as shown in dev center
  string schema_name = 4 [(.wix.api.maxLength) = 128]; // Schema name from business schema
  bool spi_component = 5; // Indicates if a component type represents a configuration of an SPI
}

message Attributes {
  bool singular = 1; // Allows more than one of that type per app
  bool non_deletable = 2; // Allows deleting
  bool non_updatable = 3; // Allows updating
}

message ComponentTypeDisplayData {
  string type = 1 [(.wix.api.maxLength) = 128]; // Component type
  string display_name = 2 [(.wix.api.maxLength) = 64]; // Name to be displayed in dev center
  repeated string labels = 3 [(.wix.api.maxSize) = 32, (.wix.api.maxLength) = 64]; // Labels of components, as shown in dev center
  Attributes attributes = 4; // Attributes for validation
  google.protobuf.StringValue description = 5 [(.wix.api.maxLength) = 512]; // Description of the component, as shown in dev center
  wix.coreservices.businessschema.v1.Exposure exposure = 6; // Exposure of the component in Dev Center. Public - open to all, Internal - open to Wix employees, Private - open to none
  google.protobuf.StringValue learn_more_link = 7 [(.wix.api.format) = WEB_URL]; // Learn more link, as shown in dev center
  bool requires_approval = 8; // If the component requires approval of dev rel team
  com.wixpress.appservice.api.ComponentData example_component_data = 9; // An example of a component data
}
