// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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 org.apache.texera.amber.engine.common;

import "org/apache/texera/amber/engine/architecture/rpc/controlcommands.proto";
import "org/apache/texera/amber/engine/architecture/rpc/controlreturns.proto";
import "org/apache/texera/amber/engine/architecture/worker/statistics.proto";
import "org/apache/texera/amber/core/virtualidentity.proto";
import "org/apache/texera/amber/core/workflowruntimestate.proto";
import "scalapb/scalapb.proto";

option (scalapb.options) = {
  scope: FILE,
  preserve_unknown_fields: false
  no_default_values_in_constructor: false
};


message BreakpointFault{
  message BreakpointTuple{
    int64 id = 1;
    bool is_input = 2;
    repeated string tuple = 3;
  }

  string worker_name = 1;
  BreakpointTuple faulted_tuple = 2;
}

message OperatorBreakpoints{
  repeated BreakpointFault unresolved_breakpoints = 1;
}

message ExecutionBreakpointStore{
  map<string, OperatorBreakpoints> operator_info = 1;
}

message EvaluatedValueList{
  repeated architecture.rpc.EvaluatedValue values = 1;
}

message OperatorConsole{
  repeated architecture.rpc.ConsoleMessage console_messages = 1;
  map<string, EvaluatedValueList> evaluate_expr_results = 2;
}

message ExecutionConsoleStore{
  map<string, OperatorConsole> operator_console = 1;
}

message OperatorWorkerMapping{
  string operatorId = 1;
  repeated string workerIds = 2;
}

message OperatorStatistics{
  repeated architecture.worker.PortTupleMetricsMapping input_metrics = 1;
  repeated architecture.worker.PortTupleMetricsMapping output_metrics = 2;
  int32 num_workers = 3;
  int64 data_processing_time = 4;
  int64 control_processing_time = 5;
  int64 idle_time = 6;
}

message OperatorMetrics{
  architecture.rpc.WorkflowAggregatedState operator_state = 1 [(scalapb.field).no_box = true];
  OperatorStatistics operator_statistics = 2 [(scalapb.field).no_box = true];
}

message ExecutionStatsStore {
  int64 startTimeStamp = 1;
  int64 endTimeStamp = 2;
  map<string, OperatorMetrics> operator_info = 3;
  repeated OperatorWorkerMapping operator_worker_mapping = 4;
}


message ExecutionMetadataStore{
  architecture.rpc.WorkflowAggregatedState state = 1;
  repeated core.WorkflowFatalError fatal_errors = 2;
  core.ExecutionIdentity executionId = 3 [(scalapb.field).no_box = true];
  bool is_recovering = 4;
}