// 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/struct.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";

// A Module applies a computer vision algorithm to a subproblem of a visual
// inspection task.
message Module {
  option (google.api.resource) = {
    type: "visualinspection.googleapis.com/Module"
    pattern: "projects/{project}/locations/{location}/solutions/{solution}/modules/{module}"
  };

  // The type of the module.
  oneof type {
    // Anomaly detection.
    AnomalyDetectionModule anomaly_detection = 8;

    // Sparse alignment localization.
    SparseAlignmentLocalizationModule sparse_alignment_localization = 9;

    // Localization refinement.
    LocalizationRefinementModule localization_refinement = 10;

    // Object detection.
    ObjectDetectionModule object_detection = 11;

    // Segmentation.
    SegmentationModule segmentation = 12;

    // Classification.
    ClassificationModule classification = 13;
  }

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

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

  // Output only. Timestamp when Module was last updated.
  google.protobuf.Timestamp update_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Required. A user friendly display name for the Module.
  // The name can be up to 128 characters long and can consist of any UTF-8
  // characters.
  string display_name = 4 [(google.api.field_behavior) = REQUIRED];

  // A description for this Module.
  string description = 5;

  // Configuration for this Module. Each Module may define its own
  // configuration options.
  google.protobuf.Struct config = 6;

  // The labels with user-defined metadata to organize your Modules.
  //
  // 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 = 7;
}

// Detailed input and output information of an anomaly detection Module.
message AnomalyDetectionModule {
  // Input regions within which to detect anomalies. If not provided, the full
  // image is used as input.
  repeated AnnotationInput query_regions = 1;

  // Required. Classification labels to train the model.
  repeated AnnotationInput classification_labels = 2
      [(google.api.field_behavior) = REQUIRED];

  // Required. Classification predictions by the model.
  repeated AnnotationOutput classification_predictions = 3
      [(google.api.field_behavior) = REQUIRED];
}

// Detailed input and output information of a sparse alignment localization
// module.
message SparseAlignmentLocalizationModule {
  // Regions within the query image to align. Multiple regions could be aligned
  // per Image.
  repeated AnnotationInput query_regions = 1;

  // Regions within the template image to transfer to the query image.
  repeated AnnotationInput target_regions = 2;

  // Regions that define the portion of the template image from which to extract
  // local features. These have both include/exclude Annotations, distinguished
  // by labels on the AnnotationSpec.
  repeated AnnotationInput inspection_regions = 3;

  // The target regions transformed by the module.
  repeated AnnotationOutput target_region_predictions = 4;

  // The inspection regions transformed by the module.
  repeated AnnotationOutput inspection_region_predictions = 5;
}

// Detailed input and output information of a localization refinment module.
message LocalizationRefinementModule {
  // Regions within the query image to align. Multiple regions could
  // be aligned per Image.
  repeated AnnotationInput query_regions = 1;

  // Regions within the template image to transfer to the query image.
  repeated AnnotationInput target_regions = 2;

  // Regions which customize the search process for each target region.
  repeated AnnotationInput local_search_regions = 3;

  // The target regions transformed by the module.
  repeated AnnotationOutput target_region_predictions = 4;

  // The inspection regions transformed by the module.
  repeated AnnotationOutput local_search_region_predictions = 5;
}

// Detailed input and output information of an object detection module.
message ObjectDetectionModule {
  // Regions to search on for the query image, anything outside of these regions
  // will not be considered from the module. These regions are defined in the
  // template image and applied "as is" to each query image. If query_regions
  // are not specified, the full image will be used as a single query region.
  repeated AnnotationInput query_regions = 1;

  // Regions within the template image to transfer to the query image.
  repeated AnnotationInput target_regions = 2;

  // Required. The regions for each object to learn the representation of.
  repeated AnnotationInput object_regions = 3
      [(google.api.field_behavior) = REQUIRED];

  // The target regions transformed by the module.
  repeated AnnotationOutput target_region_predictions = 4;

  // Required. The objects regions detected by the module.
  repeated AnnotationOutput object_region_predictions = 5
      [(google.api.field_behavior) = REQUIRED];
}

// Detailed input and output information of an image segmentation module.
message SegmentationModule {
  // Regions to search on for the query image, anything outside of these regions
  // will not be considered from the module. The query images can be defined in
  // the template image or predicted per image from other modules.  If
  // query_regions are not specified, the full image will be used as a single
  // query region.
  repeated AnnotationInput query_regions = 1;

  // Regions within the template image to transfer to the query image.
  repeated AnnotationInput inspection_regions = 2;

  // Required. The segmentation regions to learn the representation of.
  repeated AnnotationInput segmentation_regions = 3
      [(google.api.field_behavior) = REQUIRED];

  // The segmentation predictions in inspection regions by the module.
  repeated AnnotationOutput inspection_region_predictions = 4;

  // Required. The segmentation predictions by the module.
  repeated AnnotationOutput segmentation_predictions = 5
      [(google.api.field_behavior) = REQUIRED];
}

// Detailed input and output information of an image classification module.
message ClassificationModule {
  // Regions to search on for the query image, anything outside of these regions
  // will not be considered from the module. The query images can be defined in
  // the template image or predicted per image from other modules.  If
  // query_regions are not specified, the full image will be used as a single
  // query region.
  repeated AnnotationInput query_regions = 1;

  // Regions within the template image to transfer to the query image.
  repeated AnnotationInput inspection_regions = 2;

  // Required. Classification labels to train the module.
  repeated AnnotationInput classification_labels = 3
      [(google.api.field_behavior) = REQUIRED];

  // Classification predictions in inspection regions by the module.
  repeated AnnotationOutput inspection_region_predictions = 4;

  // Required. Classification predictions by the module.
  repeated AnnotationOutput classification_predictions = 5
      [(google.api.field_behavior) = REQUIRED];
}

// Specifies the source of Annotations for a Module input.
message AnnotationInput {
  // Required. The AnnotationSet ID containing input Annotations. The expected
  // AnnotationType of this AnnotationSet will depend on the Module.
  string annotation_set_id = 1
      [deprecated = true, (google.api.field_behavior) = REQUIRED];

  // Required. The AnnotationSet containing input Annotations. The expected
  // AnnotationType of this AnnotationSet will depend on the Module.
  string annotation_set = 3 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "visualinspection.googleapis.com/AnnotationSet"
    }
  ];

  // A list of AnnotationSpecs to subselect Annotations in this AnnotationSet.
  // If specified, only Annotations which have an AnnotationSpec in the list are
  // used as input to the Module.
  repeated string annotation_spec_allowlist = 2;
}

// Specifies the output for Annotations produced by a Module.
message AnnotationOutput {
  // Required. The AnnotationSet ID containing output Annotations. The expected
  // AnnotationType of this AnnotationSet will depend on the Module.
  string annotation_set_id = 1
      [deprecated = true, (google.api.field_behavior) = REQUIRED];

  // Required. The AnnotationSet containing output Annotations. The expected
  // AnnotationType of this AnnotationSet will depend on the Module.
  string annotation_set = 2 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "visualinspection.googleapis.com/AnnotationSet"
    }
  ];
}
