/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * 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 = "proto2";

package cuttlefish;

message Duration {
  required int64 seconds = 1;
  required int32 nanos = 2;
}

//TODO(moelsherif) : This message is not used yet
enum UserType {
  GOOGLE = 0;
  EXTERNAL = 1;
}

// Proto used by Atest CLI Tool for Internal PII Users
message AtestLogEventInternal {
  // ------------------------
  // EVENT DEFINITIONS
  // ------------------------
  // Occurs immediately upon execution of atest
  message AtestStartEvent {
    optional string command_line = 1;
    repeated string test_references = 2;
    optional string cwd = 3;
    optional string os = 4;
  }

  // Occurs when atest exits for any reason
  message AtestExitEvent {
    optional Duration duration = 1;
    optional int32 exit_code = 2;
    optional string stacktrace = 3;
    optional string logs = 4;
  }

  // Occurs after a SINGLE test reference has been resolved to a test or
  // not found
  message FindTestFinishEvent {
    optional Duration duration = 1;
    optional bool success = 2;
    optional string test_reference = 3
       ;
    repeated string test_finders = 4;
    optional string test_info = 5;
  }

  // Occurs after the build finishes, either successfully or not.
  message BuildFinishEvent {
    optional Duration duration = 1;
    optional bool success = 2;
    repeated string targets = 3;
  }

  // Occurs when a single test runner has completed
  message RunnerFinishEvent {
    optional Duration duration = 1;
    optional bool success = 2;
    optional string runner_name = 3;
    message Test {
      optional string name = 1;
      optional int32 result = 2;
      optional string stacktrace = 3;
    }
    repeated Test test = 4;
  }

  // Occurs after all test runners and tests have finished
  message RunTestsFinishEvent {
    optional Duration duration = 1;
  }
  // Occurs after detection of catching bug by atest have finished
  message LocalDetectEvent {
    optional int32 detect_type = 1;
    optional int32 result = 2;
  }

  // ------------------------
  // FIELDS FOR ATESTLOGEVENT
  // ------------------------
  // user_key and run_id are both python uuid.uuid4() completely anonymous
  // and random hexadecimal strings. We cannot use normal google ids
  // (zwieback, gaia, etc) because we are an open source command line tool.
  // uuid4 provides us a unique key for grouping, which is all we need.
  optional string user_key = 1 ;
  optional string run_id = 2 ;
  optional UserType user_type = 3;
  optional string tool_name = 10;
  optional string sub_tool_name = 12;
  oneof event {
    AtestStartEvent atest_start_event = 4;
    AtestExitEvent atest_exit_event = 5;
    FindTestFinishEvent find_test_finish_event = 6;
    BuildFinishEvent build_finish_event = 7;
    RunnerFinishEvent runner_finish_event = 8;
    RunTestsFinishEvent run_tests_finish_event = 9;
    LocalDetectEvent local_detect_event = 11;
  }
}
