# -*- coding: utf-8 -*-
# Copyright 2022 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.
#
import proto  # type: ignore

from google.cloud.aiplatform_v1beta1.types import (
    completion_stats as gca_completion_stats,
)
from google.cloud.aiplatform_v1beta1.types import encryption_spec as gca_encryption_spec
from google.cloud.aiplatform_v1beta1.types import explanation
from google.cloud.aiplatform_v1beta1.types import io
from google.cloud.aiplatform_v1beta1.types import job_state
from google.cloud.aiplatform_v1beta1.types import machine_resources
from google.cloud.aiplatform_v1beta1.types import (
    manual_batch_tuning_parameters as gca_manual_batch_tuning_parameters,
)
from google.cloud.aiplatform_v1beta1.types import (
    unmanaged_container_model as gca_unmanaged_container_model,
)
from google.protobuf import struct_pb2  # type: ignore
from google.protobuf import timestamp_pb2  # type: ignore
from google.rpc import status_pb2  # type: ignore


__protobuf__ = proto.module(
    package="google.cloud.aiplatform.v1beta1", manifest={"BatchPredictionJob",},
)


class BatchPredictionJob(proto.Message):
    r"""A job that uses a
    [Model][google.cloud.aiplatform.v1beta1.BatchPredictionJob.model] to
    produce predictions on multiple [input
    instances][google.cloud.aiplatform.v1beta1.BatchPredictionJob.input_config].
    If predictions for significant portion of the instances fail, the
    job may finish without attempting predictions for all remaining
    instances.

    Attributes:
        name (str):
            Output only. Resource name of the
            BatchPredictionJob.
        display_name (str):
            Required. The user-defined name of this
            BatchPredictionJob.
        model (str):
            The name of the Model resoure that produces the predictions
            via this job, must share the same ancestor Location.
            Starting this job has no impact on any existing deployments
            of the Model and their resources. Exactly one of model and
            unmanaged_container_model must be set.
        unmanaged_container_model (google.cloud.aiplatform_v1beta1.types.UnmanagedContainerModel):
            Contains model information necessary to perform batch
            prediction without requiring uploading to model registry.
            Exactly one of model and unmanaged_container_model must be
            set.
        input_config (google.cloud.aiplatform_v1beta1.types.BatchPredictionJob.InputConfig):
            Required. Input configuration of the instances on which
            predictions are performed. The schema of any single instance
            may be specified via the
            [Model's][google.cloud.aiplatform.v1beta1.BatchPredictionJob.model]
            [PredictSchemata's][google.cloud.aiplatform.v1beta1.Model.predict_schemata]
            [instance_schema_uri][google.cloud.aiplatform.v1beta1.PredictSchemata.instance_schema_uri].
        model_parameters (google.protobuf.struct_pb2.Value):
            The parameters that govern the predictions. The schema of
            the parameters may be specified via the
            [Model's][google.cloud.aiplatform.v1beta1.BatchPredictionJob.model]
            [PredictSchemata's][google.cloud.aiplatform.v1beta1.Model.predict_schemata]
            [parameters_schema_uri][google.cloud.aiplatform.v1beta1.PredictSchemata.parameters_schema_uri].
        output_config (google.cloud.aiplatform_v1beta1.types.BatchPredictionJob.OutputConfig):
            Required. The Configuration specifying where output
            predictions should be written. The schema of any single
            prediction may be specified as a concatenation of
            [Model's][google.cloud.aiplatform.v1beta1.BatchPredictionJob.model]
            [PredictSchemata's][google.cloud.aiplatform.v1beta1.Model.predict_schemata]
            [instance_schema_uri][google.cloud.aiplatform.v1beta1.PredictSchemata.instance_schema_uri]
            and
            [prediction_schema_uri][google.cloud.aiplatform.v1beta1.PredictSchemata.prediction_schema_uri].
        dedicated_resources (google.cloud.aiplatform_v1beta1.types.BatchDedicatedResources):
            The config of resources used by the Model during the batch
            prediction. If the Model
            [supports][google.cloud.aiplatform.v1beta1.Model.supported_deployment_resources_types]
            DEDICATED_RESOURCES this config may be provided (and the job
            will use these resources), if the Model doesn't support
            AUTOMATIC_RESOURCES, this config must be provided.
        manual_batch_tuning_parameters (google.cloud.aiplatform_v1beta1.types.ManualBatchTuningParameters):
            Immutable. Parameters configuring the batch behavior.
            Currently only applicable when
            [dedicated_resources][google.cloud.aiplatform.v1beta1.BatchPredictionJob.dedicated_resources]
            are used (in other cases Vertex AI does the tuning itself).
        generate_explanation (bool):
            Generate explanation with the batch prediction results.

            When set to ``true``, the batch prediction output changes
            based on the ``predictions_format`` field of the
            [BatchPredictionJob.output_config][google.cloud.aiplatform.v1beta1.BatchPredictionJob.output_config]
            object:

            -  ``bigquery``: output includes a column named
               ``explanation``. The value is a struct that conforms to
               the
               [Explanation][google.cloud.aiplatform.v1beta1.Explanation]
               object.
            -  ``jsonl``: The JSON objects on each line include an
               additional entry keyed ``explanation``. The value of the
               entry is a JSON object that conforms to the
               [Explanation][google.cloud.aiplatform.v1beta1.Explanation]
               object.
            -  ``csv``: Generating explanations for CSV format is not
               supported.

            If this field is set to true, either the
            [Model.explanation_spec][google.cloud.aiplatform.v1beta1.Model.explanation_spec]
            or
            [explanation_spec][google.cloud.aiplatform.v1beta1.BatchPredictionJob.explanation_spec]
            must be populated.
        explanation_spec (google.cloud.aiplatform_v1beta1.types.ExplanationSpec):
            Explanation configuration for this BatchPredictionJob. Can
            be specified only if
            [generate_explanation][google.cloud.aiplatform.v1beta1.BatchPredictionJob.generate_explanation]
            is set to ``true``.

            This value overrides the value of
            [Model.explanation_spec][google.cloud.aiplatform.v1beta1.Model.explanation_spec].
            All fields of
            [explanation_spec][google.cloud.aiplatform.v1beta1.BatchPredictionJob.explanation_spec]
            are optional in the request. If a field of the
            [explanation_spec][google.cloud.aiplatform.v1beta1.BatchPredictionJob.explanation_spec]
            object is not populated, the corresponding field of the
            [Model.explanation_spec][google.cloud.aiplatform.v1beta1.Model.explanation_spec]
            object is inherited.