class Task:
    """
    Represents a task in the OODA (Observe, Orient, Decide, Act) loop.

    Attributes
        goal: The goal of the task.
        subtasks: A list of subtasks associated with the task.
        parent: The parent task of the current task.
        ooda_loop: The OODA loop to which the task belongs.
        result: The result of the task.
        resources: Additional resources associated with the task.

    """

    class Result:
        """
        Represents the result of a task.

        Attributes
            status: The status of the task result.
            response: The response generated by the task.
            references: A list of references related to the task.
            metrics: Metrics associated with the task.
            additional_info: Additional information about the task result.

        """

        def __init__(
            self,
            status="pending",
            response=None,
            references=None,
            metrics=None,
            additional_info=None,
        ):
            self.status = status
            self.response = response
            self.references = references if references else []
            self.metrics = metrics if metrics else {}
            self.additional_info = additional_info if additional_info else {}

    def __init__(self, goal, parent=None):
        self.goal = goal
        self.subtasks = []
        self.parent = parent
        self.ooda_loop = None
        self.result = self.Result()
        self.resources = {}

    @property
    def result(self):
        if self._result is None:
            self._result = self.Result()
        return self._result

    @result.setter
    def result(self, value):
        self._result = value

    @property
    def status(self):
        return self.result.status

    @status.setter
    def status(self, value):
        self.result.status = value

    @property
    def ooda_loop(self):
        if self.has_subtasks():
            return None
        return self._ooda_loop

    @ooda_loop.setter
    def ooda_loop(self, value):
        if self.has_subtasks():
            raise RuntimeError("Cannot set OODA loop for task with subtasks")

        self._ooda_loop = value

    def has_ooda_loop(self):
        return self.ooda_loop is not None

    def has_subtasks(self):
        return self.subtasks is not None and len(self.subtasks) > 0

    def add_subtask(self, subtask):
        if self.has_ooda_loop():
            raise RuntimeError("Cannot add subtask to task with OODA loop")

        if self.subtasks is None:
            self.subtasks = []

        self.subtasks.append(subtask)
        subtask.parent = self
