/*
 * Copyright 2020-2020 Exactpro (Exactpro Systems Limited)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto3";

package util;

import "th2_grpc_common/common.proto";

option java_multiple_files = true;
option java_package = "com.exactpro.th2.util.grpc";

service MessageComparator {
  // Compares a filter vs passed messages and returns comparison result for every pair.
  rpc compareFilterVsMessages (CompareFilterVsMessagesRequest) returns (CompareFilterVsMessagesResponse);
  // Compares a message vs another message and returns a comparison result.
  rpc compareMessageVsMessage (CompareMessageVsMessageRequest) returns (CompareMessageVsMessageResponse);
}

//--// Settings //--//
message ComparisonSettings {
  /*
  * These fields will not be considered during comparison. It concerns fields with simple or collection types.
  * Comparison result will have the NA status for them.
  */
  repeated string ignore_fields = 1;
}

//--// Compare filter versus messages //--//

message CompareFilterVsMessagesRequest {
  MessageFilter filter = 1;
  repeated Message messages = 2;
  ComparisonSettings settings = 3;
}

message CompareFilterVsMessagesResponse {
  repeated CompareFilterVsMessageResult comparison_results = 1;
}

message CompareFilterVsMessageResult {
  MessageID message_id = 1;
  ComparisonEntry comparison_result = 2;
}

//--// Compare message versus message //--//

message CompareMessageVsMessageRequest {
  repeated CompareMessageVsMessageTask comparison_tasks = 1;
}

message CompareMessageVsMessageResponse {
  repeated CompareMessageVsMessageResult comparison_results = 1;
}

message CompareMessageVsMessageTask {
  Message first = 1;
  Message second = 2;
  ComparisonSettings settings = 3;
}

message CompareMessageVsMessageResult {
  MessageID first_message_id = 1;
  MessageID second_message_id = 2;
  ComparisonEntry comparison_result = 3;
}

//--// Common entry //--//

message ComparisonEntry {
  /* The type field has default value for a root element and it should be skipped during analyse. It has real value for other fields. */
  ComparisonEntryType type = 1;
  /*
  * The status field has default value for a element with collection type and it should be skipped during analyse.
  * It has real value for other fields. Fields with nested elements have aggregated value.
  */
  ComparisonEntryStatus status = 2;
  /* The first field has default value for a root element and it should be skipped during analyse. It has value of the first message of filter in other cases. */
  string first = 3;
  /* The second field has default value for a root element and it should be skipped during analyse. It has value of the second message in other cases. */
  string second = 4;
  /*
  * The operation field has default value for a root element and it should be skipped during analyse.
  * This value is taken from filter in case filter vs message comparison or it is EQUAL in case message vs message comparison.
  */
  FilterOperation operation = 5;
  /*
  * The is_key field has default value for a root element and it should be skipped during analyse.
  * It is taken from filter in case filter versus message comparison otherwise it is false.
  */
  bool is_key = 6;
  /* The fields contains mapping name to ComparisonEntry for nested fields. */
  map<string, ComparisonEntry> fields = 7;
}

enum ComparisonEntryType {
  FIELD = 0;
  COLLECTION = 1;
}

enum ComparisonEntryStatus {
  NA = 0;
  PASSED = 1;
  FAILED = 2;
}
