/**
 * The MIT License (MIT)
 * Copyright (c) 2016-2017 Intel Corporation
 * Copyright (c) 2020-2023 Omics Data Automation, Inc.
 * Copyright (c) 2023 dātma, inc™
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of 
 * this software and associated documentation files (the "Software"), to deal in 
 * the Software without restriction, including without limitation the rights to 
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 
 * the Software, and to permit persons to whom the Software is furnished to do so, 
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all 
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/**
 * To build, use protocol buffer version >3.2.0 and the following command from base directory:
 * $ protoc -Isrc/resources/ --java_out=src/main/java/ src/resources/genomicsdb_export_config.proto
 */

syntax = "proto2";

import "genomicsdb_coordinates.proto";
import "genomicsdb_vid_mapping.proto";
import "genomicsdb_callsets_mapping.proto";

option java_package = "org.genomicsdb.model";
option java_outer_classname = "GenomicsDBExportConfiguration";

option go_package = "protobuf/";

package genomicsdb_pb;

message GenomicsDBColumnOrIntervalList {
  repeated GenomicsDBColumnOrInterval column_or_interval_list = 1;
}

message RowRange {
  required int64 low = 1;
  required int64 high = 2;
}

message RowRangeList {
  repeated RowRange range_list = 1;
}

message SparkConfig {
  optional int64 query_block_size = 1;
  optional int64 query_block_size_margin = 2;
}

message AnnotationSource {
  required string filename = 1;
  required string data_source = 2;
  repeated string attributes = 3;
  optional bool is_vcf = 4 [default = true];
  repeated string file_chromosomes = 5;
}

// Simple query configuration for GenomicsDB::query_variant_calls
// for the class initialized with ExportConfiguration below
message QueryConfiguration {
  oneof array {
    string array_name = 2;
    bool generate_array_name_from_partition_bounds = 3 [default = true];
  }

  // Only one of the following two fields must be defined
  // query_contig_intervals is recommended for use
  repeated GenomicsDBColumnOrIntervalList query_column_ranges = 5;
  repeated ContigInterval query_contig_intervals = 6;

  // Only one of the following two fields must be defined
  repeated RowRangeList query_row_ranges = 7;
  repeated string query_sample_names = 8;

  repeated string attributes = 9;
  optional string query_filter = 10;
}

message ExportConfiguration {
  required string workspace = 1;
  optional string reference_genome = 4;

  // Protobuf does have extensions, but they don't allow for templated C++ methods to operate on
  // QueryConfiguration and ExportConfiguration interchangeably. We could create yet another
  // BaseConfiguration and get both Query and ExportConfiguration to extend the Base. But, for now,
  // copying QueryConfiguration here. Note that the following fields should be identical to QueryConfiguration.

  /**** QueryConfiguration = START */
  oneof array {
    string array_name = 2;
    bool generate_array_name_from_partition_bounds = 3 [default = true];
  }

  // Only one of the following two fields must be defined
  // query_contig_intervals is recommended for use
  repeated GenomicsDBColumnOrIntervalList query_column_ranges = 5;
  repeated ContigInterval query_contig_intervals = 6;

  // Only one of the following two fields must be defined
  repeated RowRangeList query_row_ranges = 7;
  repeated string query_sample_names = 8;

  repeated string attributes = 9;
  optional string query_filter = 10;
  /**** QueryConfiguration - END */

  optional string vcf_header_filename = 11;
  optional string vcf_output_filename = 12;
  optional string vcf_output_format = 13;

  oneof vid_mapping_info {
    string vid_mapping_file = 14;
    VidMappingPB vid_mapping = 15; 
  }
  oneof callset_mapping_info {
    string callset_mapping_file = 16;
    CallsetMappingPB callset_mapping = 17;
  }

  // Other configuration
  optional uint32 max_diploid_alt_alleles_that_can_be_genotyped = 18;
  optional uint32 max_genotype_count = 19;
  optional bool index_output_VCF = 20; 
  optional bool produce_GT_field = 21;
  optional bool produce_FILTER_field = 22;
  optional bool sites_only_query = 23;
  optional bool produce_GT_with_min_PL_value_for_spanning_deletions = 24;
  optional bool scan_full = 25;
  optional uint32 segment_size = 26 [default = 10485760];
  optional uint32 combined_vcf_records_buffer_size_limit = 27;
  optional bool enable_shared_posixfs_optimizations = 28 [default = false];
  optional bool bypass_intersecting_intervals_phase = 29 [default = false];
  optional SparkConfig spark_config = 30;
  repeated AnnotationSource annotation_source = 31;
  optional uint32 annotation_buffer_size = 32 [default = 10240];
}
