syntax = "proto3";

package wix.fedinfra.exportservice.v1;
option java_package = "com.wixpress.fedinfra.exportservice.v1";

import "google/protobuf/wrappers.proto";
import "google/protobuf/struct.proto";
import "wix/api/validations.proto";
import "wix/api/entity.proto";
import "wix/infra/asyncjobs/v1/AsyncJob.proto";
import "google/protobuf/timestamp.proto";
import "wix/common/query.proto";
import "wix/common/paging.proto";
import "wix/api/api_errors.proto";
import "wix/api/errors.proto";
import "wix/fedinfra/exportservicespi/v1/export_query_v2.proto";

message ExportAsyncJob {
  option (wix.api.entity) = {
    fqdn: "wix.fedinfra.exportservice.v1.export_async_job"
    segment: USERS
    appendix_files: {
      type: AUTO_VELO
      path: "appendices/velo"
    }
  };

  string id = 1 [(wix.api.format) = GUID, (wix.api.readOnly) = true];

  ExportAsyncJobData data = 3;

  .wix.infra.asyncjobs.v1.AsyncJob.Status status = 4;

  google.protobuf.Timestamp create_date = 6 [(wix.api.readOnly) = true];
  google.protobuf.Timestamp update_date = 7 [(wix.api.readOnly) = true];
}

enum ArrayFieldDelimiter {
  SEMICOLON = 0;
  SEMICOLON_AND_SPACE = 1;
}

message ExportAsyncJobData {
  // original request data for the export
  .wix.fedinfra.exportservicespi.v1.ExportQueryV2 query = 1; // WQL expression
  repeated FieldDescriptor fields = 2; // translated CSV headers
  ArrayFieldDelimiter array_field_delimiter = 18;
  MethodMetadata method_metadata = 3; // The target method to query data from
  MethodSpec method_spec = 4; // Custom spec for the target method's request/response

  string user_id = 14;
  .google.protobuf.StringValue sub_dir = 15;

  string format = 6;
  string upload_id = 7;
  .google.protobuf.StringValue save_as = 13 [(.wix.api.maxLength) = 255];

  // the progress of fetching all data update during the process multiple times
  .wix.common.PagingMetadataV2 paging_metadata = 8;
  int32 iterations_count = 9;
  int32 processed_items_count = 16;
  .google.protobuf.StringValue completion_step = 17;
  // how many times the export was reset
  int32 reset_count = 10;

  // at final step update the signed_url to download the result from
  string signed_url = 11;
  // when failed during the process update the error details
  .wix.api.Details error = 12;

  .google.protobuf.Struct test_params = 20;
}

message FieldDescriptor {
  string id = 1; // the path to the field out of the query response items
  string header = 2; // how to present the filed in the CSV headers (translated)
}

message MethodMetadata {
  string artifact = 1;
  string service = 2;
  string method = 3;
}

message MethodSpec {
  QueryFieldNumber request_query_field_number = 1;
  .google.protobuf.StringValue response_repeated_field_name = 2;
  .google.protobuf.StringValue response_paging_metadata_field_name = 3;

  enum QueryFieldNumber {
    DEFAULT = 0; // message QuerySomethingRequest { .wix.common.QueryV2 query = 1; }
    FIELD_2 = 2;
    FIELD_3 = 3;
    FIELD_4 = 4;
    FIELD_5 = 5;
    FIELD_6 = 6;
    FIELD_7 = 7;
    FIELD_8 = 8; // message QuerySomethingRequest { .wix.common.QueryV2 query = 8; }
    FIELD_9 = 9;
  }
}
