syntax = "proto3";

package wix.devcenter.apps.components.validator;

import "wix/spi/definitions.proto";
import "wix/api/validations.proto";
import "google/protobuf/struct.proto";
import "google/api/annotations.proto";
import "google/protobuf/wrappers.proto";
import "wix/devcenter/apps/components/v1/component.proto";
import "wix/devcenter/apps/components/validator/components_validator_config.proto";

service ComponentsValidator {
  option (.wix.spi.service) = {
    spi_identifier: "com.wixpress.appservice.api.ComponentType.COMPONENTS_VALIDATOR_PROVIDER",
    config_message: "wix.devcenter.apps.components.validator.ComponentsValidatorConfig",
    host_service: "wix.devcenter.apps.components.v1.ComponentsService",
    fqdn: "wix.interfaces.components_validator.v1.validation_provider",
    app_id: "9de1f02b-cfe9-4ff1-a016-c5e270977576"
  };

  // Validate component before any SDL operation
  rpc ValidateComponents (ValidateComponentsRequest) returns (ValidateComponentsResponse) {
    option (.google.api.http).post = "/v1/validate-components";
  };
}

message ValidateComponentsRequest {
  repeated wix.devcenter.apps.components.v1.Component requested_components = 1 [(.wix.api.maxSize) = 100]; // components that have been created or have been modified
  repeated wix.devcenter.apps.components.v1.Component current_app_components = 2 [(.wix.api.maxSize) = 512]; // current components on the app
  TriggerFlow trigger_flow = 3; // Indicates what flow trigger this operation on the components
  google.protobuf.StringValue components_override_id = 4 [(wix.api.maxLength) = 50]; // ID of the relevant ComponentsOverride
}

message ValidateComponentsResponse {
  repeated ComponentValidationResult results = 1; // list of validation results
}

message ComponentValidationResult {
  string component_id = 1 [(.wix.api.format) = GUID]; // component ID
  bool valid = 2; // validation result
  google.protobuf.Struct error = 3; // the error as a result of the validation
  google.protobuf.StringValue message = 4; // a user facing human readable error message
}

enum TriggerFlow {
  UNKNOWN_TRIGGER_FLOW = 0;
  CLONE = 1;
}