// Copyright 2020 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.cloud.visualinspection.v1beta1;

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

option csharp_namespace = "Google.Cloud.VisualInspection.V1Beta1";
option php_namespace = "Google\\Cloud\\VisualInspection\\V1beta1";
option ruby_package = "Google::Cloud::VisualInspection::V1beta1";
option go_package = "google.golang.org/genproto/googleapis/cloud/visualinspection/v1beta1;visualinspection";
option java_multiple_files = true;
option java_package = "com.google.cloud.visualinspection.v1beta1";

// Labeling job to trigger human labeling for adding annotations to images.
message LabelingJob {
  option (google.api.resource) = {
    type: "visualinspection.googleapis.com/LabelingJob"
    pattern: "projects/{project}/locations/{location}/labelingJobs/{labeling_job}"
  };

  // Describes the state of a labeling job.
  enum JobState {
    // The job state is unspecified.
    JOB_STATE_UNSPECIFIED = 0;

    // The job has been just created or resumed and processing has not yet
    // begun.
    JOB_STATE_QUEUED = 1;

    // The service is preparing to run the job.
    JOB_STATE_PENDING = 2;

    // The job is in progress.
    JOB_STATE_RUNNING = 3;

    // The job completed successfully.
    JOB_STATE_SUCCEEDED = 4;

    // The job failed.
    JOB_STATE_FAILED = 5;

    // The job is being cancelled. From this state the job may only go to
    // either JOB_STATE_SUCCEEDED, JOB_STATE_FAILED or JOB_STATE_CANCELLED.
    JOB_STATE_CANCELLING = 6;

    // The job has been cancelled.
    JOB_STATE_CANCELLED = 7;

    // The job has been stopped, and can be resumed.
    JOB_STATE_PAUSED = 8;
  }

  oneof labeling_config {
    // Optional. Labeling Config for `AnomalyDetection` module.
    AnomalyDetectionLabelingConfig anomaly_detection_labeling_config = 3
        [(google.api.field_behavior) = OPTIONAL];
  }

  // Output only. Resource name of the LabelingJob.
  string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Required. The user-defined name of the LabelingJob.
  // The name can be up to 128 characters long and can be consist of any UTF-8
  // characters.
  // Display name of a LabelingJob.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The resource name of an existing AnnotationSet for all
  // annotations created through this labeling job. The corresponding
  // AnnotationSet needs to match the `labeling_config`, e.g.,
  // AnomalyDetectionLabelingConfig needs AnnotationSet with
  // `classification_label` specified. Format:
  //
  // projects/{project}/locations/{location}/datasets/{dataset}/annotationSets/{annotation_set}.
  string output_annotation_set = 4 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "visualinspection.googleapis.com/AnnotationSet"
    }
  ];

  // Required. The Google Cloud Storage location of the instruction PDF. This
  // pdf is shared with labelers, and provides detailed description on how to
  // label.
  string instruction_uri = 5 [(google.api.field_behavior) = REQUIRED];

  // Required. The full resource name of annotation specs that will be used for
  // labeling. Format
  //
  // `projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}`.
  repeated string annotation_specs = 6 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "visualinspection.googleapis.com/AnnotationSpec"
    }
  ];

  // Optional. The SpecialistPools' resource names associated with this job.
  repeated string specialist_pools = 7 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The active learning config, e.g., maximum number of items to
  // label.
  ActiveLearningConfig active_learning_config = 8
      [(google.api.field_behavior) = OPTIONAL];

  // Output only. The detailed state of the job.
  JobState state = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Current labeling job progress percentage scaled in interval
  // [0, 100], indicating the percentage of DataItems that has been finished.
  int32 labeling_progress = 10 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp when this LabelingJob was created.
  google.protobuf.Timestamp create_time = 11
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp when this LabelingJob was updated most recently.
  google.protobuf.Timestamp update_time = 12
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The labels with user-defined metadata to organize your
  // LabelingJob.
  //
  // Label keys and values can be no longer than 64 characters
  // (Unicode codepoints), can only contain lowercase letters, numeric
  // characters, underscores and dashes. International characters are allowed.
  // Label keys must start with a letter.
  //
  // See https://goo.gl/xmQnxf for more information on and examples of labels.
  map<string, string> labels = 13 [(google.api.field_behavior) = OPTIONAL];
}

// Configuration of active learning.
message ActiveLearningConfig {
  // Max number of human labeled data items.
  int64 max_item_count = 1;
}

// Labeling configuration of anomaly detection.
message AnomalyDetectionLabelingConfig {
  // Required. The bounding box annotation set for anomaly detection module.
  // Format:
  //
  // projects/{project}/locations/{location}/datasets/{dataset}/annotationSets/{annotation_set}.
  repeated string input_bounding_box_annotation_sets = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "visualinspection.googleapis.com/AnnotationSet"
    }
  ];

  // A list of AnnotationSpecs to subselect Annotations in
  // `input_bounding_box_annotation_sets`. If specified, only Annotations which
  // have an AnnotationSpec in the list will be used for labeling. Format:
  //
  // `projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}`.
  repeated string annotation_spec_allowlist = 2
      [(google.api.resource_reference) = {
        type: "visualinspection.googleapis.com/AnnotationSpec"
      }];
}

// SpecialistPool represents customers' own workforce to work on their data
// labeling jobs. It includes a group of specialist managers who are responsible
// for managing the labelers in this pool as well as customers' data labeling
// jobs associated with this pool.
// Customers create specialist pool as well as start data labeling jobs on
// Cloud, managers and labelers work with the jobs using CrowdCompute console.
message SpecialistPool {
  option (google.api.resource) = {
    type: "visualinspection.googleapis.com/SpecialistPool"
    pattern: "projects/{project}/locations/{location}/specialistPools/{specialist_pool}"
  };

  // Output only. Resource name for the SpecialistPool.
  string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Required. A user friendly display name for the Dataset.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Output only. The number of Specialists in this SpecialistPool.
  int32 specialist_managers_count = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // The email addresses of the specialists in the SpecialistPool.
  repeated string specialist_manager_emails = 4;
}
