/*
 * Copyright 2020-2021 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";

import "th2_grpc_common/common.proto";

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


service Check1 {
    rpc createCheckpoint (CheckpointRequest) returns (CheckpointResponse) {}
    rpc submitCheckRule (CheckRuleRequest) returns (CheckRuleResponse) {}
    rpc submitCheckSequenceRule(CheckSequenceRuleRequest) returns (CheckSequenceRuleResponse) {}
    rpc submitNoMessageCheck(NoMessageCheckRequest) returns (NoMessageCheckResponse) {}
}

message CheckpointRequest {
    string description = 1;
    EventID parent_event_id = 2;
}

message CheckpointResponse {
    Checkpoint checkpoint = 1;
    RequestStatus status = 2;
}

message ChainID {
    string id = 1;
}

message CheckRuleRequest {
    ConnectionID connectivity_id = 1;
    oneof kind {
      /*
      * This filter will be converted to the RootMessageFilter.
      * The field will be removed in future releases
      */
      MessageFilter filter = 2 [deprecated = true];
      RootMessageFilter root_filter = 10;
    }
    Checkpoint checkpoint = 3; // Registered Checkpoint. If the chain_id is also set in the request the checkpoint will be ignored
    int64 timeout = 4; // Timeout for rule execution
    reserved 5; // ReportId reportId = 5; reserved now
    EventID parent_event_id = 6;
    string description = 7;
    Direction direction = 8;
    ChainID chain_id = 9; // The chain id to continue checking.
                          // If it's not set the check will be started from the specified checkpoint otherwise checkpoint will be ignored
}

message CheckRuleResponse {
    RequestStatus status = 1;
    ChainID chain_id = 2; // You can use it to unite the next rule to the chain with currently submitted one
}

message CheckSequenceRuleRequest {
    PreFilter pre_filter = 1;
    /*
    * This filters will be converted to root_filters if they are not set.
    * If message_filters and root_filters are both set the error response will be returned.
    */
    repeated MessageFilter message_filters = 2 [deprecated = true];
    /*
    * Either this field or message_filters must be set. If both are set the error response will be received from check1
    */
    repeated RootMessageFilter root_message_filters = 12;
    Checkpoint checkpoint = 3; // Registered Checkpoint. If the chain_id is also set in the request the checkpoint will be ignored
    int64  messageTimeout = 13; // Timeout to wait for messages after checkpoint
    int64 timeout = 4; // Timeout for rule execution
    ConnectionID connectivity_id = 5;
    reserved 6; // ReportId reportId = 5; reserved now
    EventID parent_event_id = 7;
    bool check_order = 8;
    string description = 9;
    Direction direction = 10;
    ChainID chain_id = 11; // The chain id to continue checking.
                           // If it's not set the check will be started from the specified checkpoint otherwise checkpoint will be ignored
}

message CheckSequenceRuleResponse {
    RequestStatus status = 1;
    ChainID chain_id = 2; // You can use it to unite the next rule to the chain with currently submitted one
}

message PreFilter {
    reserved 1; // don't know why we skipped it but just in case we should reserve this index
    map<string, ValueFilter> fields = 2;
    MetadataFilter metadata_filter = 3;
}

message NoMessageCheckRequest {
    PreFilter pre_filter = 1;
    int64  messageTimeout = 2; // Timeout to wait for messages after checkpoint
    int64 timeout = 3; // Timeout for rule execution
    Checkpoint checkpoint = 4; // Registered Checkpoint. If the chain_id is also set in the request the checkpoint will be ignored
    ChainID chain_id = 5; // You can use it to unite the next rule to the chain with currently submitted one
    ConnectionID connectivity_id = 6;
    EventID parent_event_id = 7;
    string description = 8;
    Direction direction = 9;
}

message NoMessageCheckResponse {
    RequestStatus status = 1;
    ChainID chain_id = 2; // You can use it to unite the next rule to the chain with currently submitted one
}