// Copyright 2022 The MediaPipe Authors. All Rights Reserved.
//
// 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.

package com.google.mediapipe.tasks.vision.imageclassifier;

import com.google.auto.value.AutoValue;
import com.google.mediapipe.tasks.components.containers.ClassificationResult;
import com.google.mediapipe.tasks.components.containers.proto.ClassificationsProto;
import com.google.mediapipe.tasks.core.TaskResult;

/** Represents the classification results generated by {@link ImageClassifier}. */
@AutoValue
public abstract class ImageClassifierResult implements TaskResult {

  /**
   * Creates an {@link ImageClassifierResult} instance.
   *
   * @param classificationResult the {@link ClassificationResult} object containing one set of
   *     results per classifier head.
   * @param timestampMs a timestamp for this result.
   */
  static ImageClassifierResult create(ClassificationResult classificationResult, long timestampMs) {
    return new AutoValue_ImageClassifierResult(classificationResult, timestampMs);
  }

  /**
   * Creates an {@link ImageClassifierResult} instance from a {@link
   * ClassificationsProto.ClassificationResult} protobuf message.
   *
   * @param proto the {@link ClassificationsProto.ClassificationResult} protobuf message to convert.
   * @param timestampMs a timestamp for this result.
   */
  // TODO: consolidate output formats across platforms.
  static ImageClassifierResult createFromProto(
      ClassificationsProto.ClassificationResult proto, long timestampMs) {
    return create(ClassificationResult.createFromProto(proto), timestampMs);
  }

  /** Contains one set of results per classifier head. */
  public abstract ClassificationResult classificationResult();

  @Override
  public abstract long timestampMs();
}
