# Copyright (c) IBM Corporation
# SPDX-License-Identifier: MIT

import typing

import pydantic

import orchestrator.modules
from orchestrator.core.operation.resource import (
    OperationExitStateEnum,
    OperationResource,
    OperationResourceEventEnum,
    OperationResourceStatus,
)

if typing.TYPE_CHECKING:
    import orchestrator.modules.operators.base


class OperationException(Exception):

    def __init__(
        self,
        message,
        operation: OperationResource,
        *args,
    ):
        self.operation = operation
        super().__init__(message, operation, *args)


class OperationOutput(pydantic.BaseModel):
    metadata: dict = pydantic.Field(
        default={},
        description="Metadata about the operation. "
        "Should be added to the metadata of the OperationResource",
    )
    resources: list[orchestrator.core.resources.ADOResource] = pydantic.Field(
        default=[],
        description="Array of ADO resources generated by the operation",
    )
    other: list[typing.Any] = pydantic.Field(
        default=[],
        description="Any non-resource objects",
    )
    operation: OperationResource = pydantic.Field(
        default=None,
        description="Optional:The operation resource that created this output",
    )
    exitStatus: OperationResourceStatus = pydantic.Field(
        description="Exit status of the operation. Default to success if not applied",
        default=OperationResourceStatus(
            message="This is a default status",
            exit_state=OperationExitStateEnum.SUCCESS,
            event=OperationResourceEventEnum.FINISHED,
        ),
    )
