// Copyright 2026 Google LLC
//
// 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 google.chromeos.moblab.v1beta1;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option go_package = "google.golang.org/genproto/googleapis/chromeos/moblab/v1beta1;moblab";
option java_multiple_files = true;
option java_outer_classname = "ResourcesProto";
option java_package = "com.google.chromeos.moblab.v1beta1";
option optimize_for = SPEED;

// Resource that represents a build target.
// -- NEXT_TAG: 2 --
message BuildTarget {
  option (google.api.resource) = {
    type: "chromeosmoblab.googleapis.com/BuildTarget"
    pattern: "buildTargets/{build_target}"
  };

  // The resource name of the build target.
  // Format: buildTargets/{build_target}
  string name = 1;
}

// Resource that represents a model. Each model belongs to a build target. For
// non-unified build, the model name is the same as its build target name.
// -- NEXT_TAG: 2 --
message Model {
  option (google.api.resource) = {
    type: "chromeosmoblab.googleapis.com/Model"
    pattern: "buildTargets/{build_target}/models/{model}"
  };

  // The resource name of the model.
  // Format: buildTargets/{build_target}/models/{model}
  string name = 1;
}

// Resource that represents a chrome OS milestone.
// -- NEXT_TAG: 2 --
message Milestone {
  option (google.api.resource) = {
    type: "chromeosmoblab.googleapis.com/Milestone"
    pattern: "milestones/{milestone}"
  };

  // The resource name of the milestone.
  // Format: milestones/{milestone}
  string name = 1;
}

// Resource that represents a build for the given build target, model, milestone
// and build version.
// -- NEXT_TAG: 9 --
message Build {
  option (google.api.resource) = {
    type: "chromeosmoblab.googleapis.com/Build"
    pattern: "buildTargets/{build_target}/models/{model}/builds/{build}"
  };

  // The build status types.
  enum BuildStatus {
    // No build status is specified.
    BUILD_STATUS_UNSPECIFIED = 0;

    // Complete Status: The build passed.
    PASS = 1;

    // Complete Status: The build failed.
    FAIL = 2;

    // Intermediate Status: The build is still running.
    RUNNING = 3;

    // Complete Status: The build was aborted.
    ABORTED = 4;
  }

  // The build types.
  enum BuildType {
    // Invalid build type.
    BUILD_TYPE_UNSPECIFIED = 0;

    // The release build.
    RELEASE = 1;

    // The firmware build.
    FIRMWARE = 2;
  }

  // The resource name of the build.
  // Format: buildTargets/{build_target}/models/{model}/builds/{build}
  // Example: buildTargets/octopus/models/bobba/builds/1234.0.0
  string name = 1;

  // The milestone that owns the build.
  // Format: milestones/{milestone}
  string milestone = 2 [(google.api.resource_reference) = {
    type: "chromeosmoblab.googleapis.com/Milestone"
  }];

  // The build version of the build, e.g. 1234.0.0.
  string build_version = 3;

  // The status of the build.
  BuildStatus status = 4;

  // The type of the build.
  BuildType type = 5;

  // The branch of the build.
  string branch = 6;

  // The firmware version of the software that is flashed to the chip on the
  // Chrome OS device.
  string rw_firmware_version = 7;

  // The labels of the build.
  repeated string labels = 8;
}

// Resource that represents a build artifact stored in Google Cloud Storage for
// the given build target, model, build version and bucket.
// -- NEXT_TAG: 6 --
message BuildArtifact {
  option (google.api.resource) = {
    type: "chromeosmoblab.googleapis.com/BuildArtifact"
    pattern: "buildTargets/{build_target}/models/{model}/builds/{build}/artifacts/{artifact}"
  };

  // The resource name of the build artifact.
  // Format:
  // buildTargets/{build_target}/models/{model}/builds/{build}/artifacts/{artifact}
  // Example:
  // buildTargets/octopus/models/bobba/builds/1234.0.0/artifacts/chromeos-moblab-peng-staging
  string name = 1;

  // The build metadata of the build artifact.
  string build = 2 [(google.api.resource_reference) = {
    type: "chromeosmoblab.googleapis.com/Build"
  }];

  // The bucket that stores the build artifact.
  string bucket = 3;

  // The path of the build artifact in the bucket.
  string path = 4;

  // The number of objects in the build artifact folder. The object number can
  // be used to calculated the stage progress by comparing the source build
  // artifact with the destination build artifact.
  uint32 object_count = 5;
}

// Cloud build message for staging a build artifact.
// This message is partially copied from the source proto
// devtools/cloudbuild/v1/cloudbuild.proto
// -- NEXT_TAG: 6 --
message CloudBuild {
  // The CloudBuild states.
  enum State {
    // No cloud build state is specified.
    STATE_UNSPECIFIED = 0;

    // The cloud build is queued.
    QUEUED = 1;

    // The cloud build is pending.
    PENDING = 2;

    // The cloud build is working.
    WORKING = 3;

    // The cloud build is successful.
    SUCCEEDED = 4;

    // The cloud build is failed.
    FAILED = 5;

    // The cloud build is failed due to internal error.
    INTERNAL_ERROR = 6;

    // The cloud build is failed due to timeout.
    TIMEOUT = 7;

    // The cloud build is cancelled.
    CANCELLED = 8;

    // The cloud build is expired.
    EXPIRED = 9;
  }

  // Output only. Unique identifier of the cloud build.
  string id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. State of the cloud build.
  State status = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Time at which the request to create the build was received.
  google.protobuf.Timestamp create_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Time at which execution of the build was started.
  google.protobuf.Timestamp start_time = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Time at which execution of the build was finished.
  //
  // The difference between finish_time and start_time is the duration of the
  // build's execution.
  google.protobuf.Timestamp finish_time = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// A session to run on-demand tests.
// -- NEXT_TAG: 7 --
message Session {
  option (google.api.resource) = {
    type: "moblab.googleapis.com/Session"
    pattern: "sessions/{session}"
    plural: "sessions"
    singular: "session"
  };

  // Identifier. The resource name of the session.
  // Format: sessions/{session}
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Optional. The ID of the Satlab that the request comes from.
  string satlab_id = 2 [(google.api.field_behavior) = OPTIONAL];

  // Required. Input only. The dimensions of the device(s) to run tests on.
  map<string, string> dimensions = 3 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.field_behavior) = INPUT_ONLY
  ];

  // Optional. Input only. The timeout settings for the test run.
  Timeout timeout = 4 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.field_behavior) = INPUT_ONLY
  ];

  // Optional. Input only. The number of shards to use for the test run.
  int32 shard_count = 5 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.field_behavior) = INPUT_ONLY
  ];

  // The test to run.
  oneof test {
    // Input only. A Tradefed-based test.
    TradefedTest tradefed_test = 6 [(google.api.field_behavior) = INPUT_ONLY];
  }
}

// Timeout settings for the test run.
// -- NEXT_TAG: 4 --
message Timeout {
  // Optional. Max execution time of a job.
  google.protobuf.Duration job_timeout = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Max execution time of a single test.
  google.protobuf.Duration test_timeout = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Timeout for starting the job and waiting for allocating the first
  // device.
  google.protobuf.Duration start_timeout = 3
      [(google.api.field_behavior) = OPTIONAL];
}

// Configuration for a Tradefed-based test.
// -- NEXT_TAG: 2 --
message TradefedTest {
  // Required. The command to run the Tradefed test.
  string command = 1 [(google.api.field_behavior) = REQUIRED];
}

// Summary information for an entire test effort
message TestEffort {
  option (google.api.resource) = {
    type: "chromeosmoblab.googleapis.com/TestEffort"
    pattern: "testEfforts/{test_effort}"
    plural: "testEfforts"
    singular: "testEffort"
  };

  // The board and model of the test effort.
  message BoardModel {
    // Required. The board name.
    string board = 1 [(google.api.field_behavior) = REQUIRED];

    // Required. The model name.
    string model = 2 [(google.api.field_behavior) = REQUIRED];
  }

  // The pool of the test effort.
  message Pool {
    // The category of pool to schedule tests against.
    enum PoolType {
      // Not used. Exists to distinguish between an unset value and DEFAULT.
      POOL_TYPE_UNSPECIFIED = 0;

      // Pools used when scheduling tests without any special exceptions
      DEFAULT_POOL = 1;

      // Pools to use when scheduling FAFT PD tests.
      FAFT_PD = 2;

      // Pools to schedule tests with extremely long runtimes (3+ hours)
      EXTENDED_DURATION = 3;
    }

    // Required. The label of the pool.
    string label = 1 [(google.api.field_behavior) = REQUIRED];

    // Required. The category of pool to schedule tests against.
    PoolType type = 2 [(google.api.field_behavior) = REQUIRED];
  }

  // Represents the Android build target.
  message AndroidBuildTarget {
    // Required. Represents the name of a configured branch in the Android Build
    // system
    string branch = 1 [(google.api.field_behavior) = REQUIRED];

    // Optional. Specifies the release configuration of the build target.
    string release_config = 2 [(google.api.field_behavior) = OPTIONAL];

    // Optional. Specifies the build variant for the target.
    string build_variant = 3 [(google.api.field_behavior) = OPTIONAL];

    // Required. The build ID of the test effort.
    string build_id = 4 [(google.api.field_behavior) = REQUIRED];

    // Optional. Product name of the build target.
    string product = 5 [(google.api.field_behavior) = OPTIONAL];
  }

  // The possible states of a test effort.
  enum State {
    // No test effort state is specified.
    STATE_UNSPECIFIED = 0;

    // The test effort is created.
    CREATED = 1;

    // The test effort has incomplete results.
    INCOMPLETE = 2;

    // The test effort has failed.
    FAILED = 3;

    // The test effort has unreported results.
    UNREPORTED = 4;

    // The test effort is not applicable.
    NOT_APPLICABLE = 5;

    // The test effort has passed.
    SUCCEEDED = 6;

    // The test effort is requested to be cancelled.
    CANCEL_REQUESTED = 7;

    // The test effort is cancelled.
    CANCELLED = 8;

    // The cancelling the test effort failed.
    CANCEL_FAILED = 9;
  }

  // The firmware type.
  enum FirmwareType {
    // No firmware type is specified.
    FIRMWARE_TYPE_UNSPECIFIED = 0;

    // The read only firmware type.
    READ_ONLY = 1;

    // The read write firmware type.
    READ_WRITE = 2;
  }

  // The version of the firmware test effort.
  message FirmwareTestEffortVersion {
    // Required. The major version of the firmware test effort.
    int32 major_version = 1 [(google.api.field_behavior) = REQUIRED];

    // Required. The minor version of the firmware test effort.
    int32 minor_version = 2 [(google.api.field_behavior) = REQUIRED];

    // Required. The patch number of the firmware test effort.
    int32 patch_number = 3 [(google.api.field_behavior) = REQUIRED];

    // Optional. The URI of the firmware.
    string uri = 4 [(google.api.field_behavior) = OPTIONAL];
  }

  // The version of the GSC test effort.
  message GscTestEffortVersion {
    // Required. The major version of the GSC test effort
    int32 major_version = 1 [(google.api.field_behavior) = REQUIRED];

    // Required. The minor version of the GSC test effort.
    int32 minor_version = 2 [(google.api.field_behavior) = REQUIRED];

    // Required. The epoch of the GSC test effort.
    int32 generation = 3 [(google.api.field_behavior) = REQUIRED];

    // Optional. The URI of the GSC.
    string uri = 4 [(google.api.field_behavior) = OPTIONAL];
  }

  // The target of the firmware.
  message FirmwareTarget {
    // The firmware content.
    oneof fw {
      // The EC firmware version.
      FirmwareTestEffortVersion ec = 1;

      // The AP firmware version.
      FirmwareTestEffortVersion ap = 2;

      // The GSC firmware version.
      GscTestEffortVersion gsc = 3;

      // The FPMCU firmware version.
      FirmwareTestEffortVersion fpmcu = 4;
    }
  }

  // The configuration of the firmware.
  message FirmwareConfig {
    // Required. The firmware target.
    FirmwareTarget firmware_target = 1 [(google.api.field_behavior) = REQUIRED];

    // Required. The firmware types.
    repeated FirmwareType firmware_types = 2
        [(google.api.field_behavior) = REQUIRED];
  }

  // Identifier. The resource name of the test effort.
  // Format: testEfforts/{test_effort}
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. The ID of the test effort.
  string test_effort_id = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The satlab ID that the test effort comes from.
  string satlab_id = 3 [(google.api.field_behavior) = OPTIONAL];

  // The test target of the test effort.
  oneof test_target {
    // The board and model of the test effort.
    BoardModel board_model = 4;
  }

  // Required. The pools of the test effort.
  repeated Pool pools = 5 [(google.api.field_behavior) = REQUIRED];

  // Required. Test plan reference.
  string test_plan = 6 [(google.api.field_behavior) = REQUIRED];

  // Specifies the Operating System build targets to test against.
  oneof os {
    // Test against an Android build.
    AndroidBuildTarget android = 7;

    // Directly specifies the build target name.
    string build_target_override = 13;
  }

  // Output only. Overall result of the test effort.
  State state = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The time when the test effort was created.
  google.protobuf.Timestamp create_time = 9
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Testhaus link.
  string testhaus_url = 10 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The firmware configuration of the test effort.
  repeated FirmwareConfig firmware_configs = 11
      [(google.api.field_behavior) = OPTIONAL];

  // Test target details if different from the main build target.
  oneof test_source {
    // Test against an Android build target.
    AndroidBuildTarget android_test_target = 12;

    // Directly specifies the test target name.
    string test_target_override = 14;
  }
}
