syntax = "proto3";

import "google/protobuf/wrappers.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";
import "wix/api/entity.proto";
import "wix/api/annotations.proto";
import "wix/api/validations.proto";
import "wix/api/permissions.proto";
import "wix/api/subscription.proto";
import "wix/api/callback.proto";
import "wix/api/action_payload.proto";
import "com/wixpress/ci/gh/api/gcb-build-event.proto";


package wix.coreservices.businessschema.v1.internal;

enum TargetType {
  NONE = 0;
  WIX_PROTO_BUNDLE_EXPORT = 1;
  WIX_APPENDIX_BUNDLE_EXPORT = 2;
  WIX_API_REGISTRY_INFO_EXPORT = 3;
}

message File {

  // The name of the file including path relative to its source repo, i.e src/main/java/com/wixpress/MyClass.java
  google.protobuf.StringValue name = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 1000];;

  // The URI of the file
  google.protobuf.StringValue uri = 2 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];;

  // The digest of the file
  google.protobuf.StringValue digest = 3 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];;

  // The size of the file in bytes
  google.protobuf.StringValue size_in_bytes = 4 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];;
}


message Target {
  option (wix.api.entity) = {
    fqdn: "wix.coreservices.internal.v1.target",
    segment: OTHERS
    domain_events_read_permission: "API_INFRA.BS_INDEXER.TARGET_DOMAIN_EVENTS_READ"
  };

  option (wix.api.domain_event) = {
    event_type: ACTION
    exposure: PRIVATE
    maturity: ALPHA
    action_message_fqn: "wix.coreservices.businessschema.v1.internal.UnprocessedTargetEvent"
 };

  // Unique identifier of the target with pattern `id_tag_value[type]`, for example 'com.wixpress.myproto[wix_proto_bundle_export]``
  google.protobuf.StringValue id = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];

  // The unique location of the target in Bazel notation i.e @repo//path/to/target:target_name
  google.protobuf.StringValue location = 2 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];

  // The combined digest of all files within the target
  google.protobuf.StringValue combined_digest = 3 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];

  // The vcs commit timestamp of the target in milliseconds
  google.protobuf.StringValue commit_timestamp = 4 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];; 

  // The vcs commit revision of the target
  google.protobuf.StringValue commit_revision = 8 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];

  // The vcs commit revision of the target
  google.protobuf.StringValue repo_url = 9 [(wix.api.minLength) = 1, (wix.api.maxLength) = 500];

  // The type of the target
  TargetType type = 5;

  // The target's id tag value in Bazel, uniquness is not guaranteed
  // i.e for a tag "businessSchemaIndexerId=com.wixpress.myproto" the value is "com.wixpress.myproto"
  google.protobuf.StringValue id_tag_value = 6 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];

  repeated File files = 7 [(wix.api.maxSize) = 1000];
}

service BusinessSchemaIndexerService {
  option (wix.api.service_entity).message = "wix.coreservices.businessschema.v1.internal.Target";
  option (wix.api.service_exposure) = PRIVATE;
  option (wix.api.service_maturity) = ALPHA;


  rpc GetProtoArtifactLastInvocationData (GetProtoArtifactLastInvocationDataRequest) returns (GetProtoArtifactLastInvocationDataResponse) {
    option (.wix.api.exposure) = PRIVATE;
    option (wix.api.required) = "GetProtoArtifactLastInvocationDataRequest.proto_artifact_id";
  }
}

message UnprocessedTargetEvent {
  option (wix.api.action_payload).custom_slug = "UNPROCESSED_TARGET";
  Target target = 1 ; 
}

message ProtoArtifactInvocationData {
  google.protobuf.StringValue proto_artifact_id = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 256]; // proto artifact id
  google.protobuf.StringValue invocation_id = 2 [(wix.api.minLength) = 1, (wix.api.maxLength) = 256]; // invocation id
  google.protobuf.StringValue ran_at = 3 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100]; // ran at timestamp in milliseconds
  google.protobuf.StringValue label = 4 [(wix.api.maxLength) = 1000];
  google.protobuf.StringValue repo_url = 5 [(wix.api.maxLength) = 1000];
  google.protobuf.StringValue github_target_path = 6 [(wix.api.maxLength) = 1000]; //github target path to build bazel file
  google.protobuf.StringValue commit_hash = 7 [(wix.api.minLength) = 1, (wix.api.maxLength) = 100];
}

message GetProtoArtifactLastInvocationDataRequest {
    string proto_artifact_id = 1 [(wix.api.minLength) = 1, (wix.api.maxLength) = 256];
}

message GetProtoArtifactLastInvocationDataResponse {
    ProtoArtifactInvocationData invocation_data = 1;
}