<commit_before># -*- coding: utf-8 -*-
"""ThreatConnect Task"""
from .assignee import Assignee
from .api_endpoints import ApiEndpoints
from .common_case_management import CommonCaseManagement
from .common_case_management_collection import CommonCaseManagementCollection
from .filter import Filter
from .tql import TQL


class Tasks(CommonCaseManagementCollection):
    """Tasks Class for Case Management Collection

    params example: {
        'result_limit': 100, # How many results are retrieved.
        'result_start': 10,  # Starting point on retrieved results.
        'fields': ['caseId', 'summary'] # Additional fields returned on the results
    }

    Args:
        tcex (TcEx): An instantiated instance of TcEx object.
        initial_response (dict, optional): Initial data in
            Case Object for Task. Defaults to None.
        tql_filters (list, optional): List of TQL filters. Defaults to None.
        params(dict, optional): Dict of the params to be sent while
            retrieving the Task objects.
    """

    def __init__(self, tcex, initial_response=None, tql_filters=None, params=None):
        """Initialize Class properties."""
        super().__init__(
            tcex,
            ApiEndpoints.TASKS,
            initial_response=initial_response,
            tql_filters=tql_filters,
            params=params,
        )

        if initial_response:
            for item in initial_response.get('data', []):
                self.added_items.append(Task(tcex, **item))

    def __iter__(self):
        """Object iterator"""
        return self.iterate(initial_response=self.initial_response)

    def add_task(self, task):
        """Add an task to a case.

        Args:
            task (Task): The Task Object to add.
        """
        self.added_items.append(task)

    def entity_map(self, entity):
        """Map a dict to a Task.

        Args:
            entity (dict): The Task data.

        Returns:
            CaseManagement.Task: An Task Object
        """
        return Task(self.tcex, **entity)

    @property
    def filter(self):
        """Return instance of FilterTasks Object."""
        return FilterTasks(ApiEndpoints.TASKS, self.tcex, self.tql)


class Task(CommonCaseManagement):
    """Task object for Case Management.

    Args:
        tcex (TcEx): An instantiated instance of TcEx object.
        artifacts (Artifact, kwargs): a list of Artifacts corresponding to the Task
        assignee (Assignee, kwargs): the user or group Assignee object for the Task
        case_id (int, kwargs): [Required (alt: caseXid)] The **Case Id** for the Task.
        case_xid (str, kwargs): [Required (alt: caseId)] The **Case Xid** for the Task.
        completed_by (str, kwargs): [Read-Only] The **Completed By** for the Task.
        completed_date (str, kwargs): the completion date of the Task
        config_playbook (str, kwargs): [Read-Only] The **Config Playbook** for the Task.
        config_task (dict, kwargs): [Read-Only] The **Config Task** for the Task.
        dependent_on_task_name (str, kwargs): [Read-Only] The **Dependent On Task Name** for the
            Task.
        description (str, kwargs): The **Description** for the Task.
        due_date (str, kwargs): the due date of the Task
        duration (int, kwargs): [Read-Only] The **Duration** for the Task.
        id_dependent_on (int, kwargs): [Read-Only] The **Id_Dependent On** for the Task.
        name (str, kwargs): [Required] The **Name** for the Task.
        notes (Note, kwargs): a list of Notes corresponding to the Task
        parent_case (Case, kwargs): [Read-Only] The **Parent Case** for the Task.
        required (bool, kwargs): [Read-Only] The **Required** flag for the Task.
        status (str, kwargs): The **Status** for the Task.
        workflow_phase (int, kwargs): the phase of the workflow
        workflow_step (int, kwargs): the step of the workflow
        xid (str, kwargs): The **Xid** for the Task.
    """

    def __init__(self, tcex, **kwargs):
        """Initialize Class properties"""
        super().__init__(tcex, ApiEndpoints.TASKS, kwargs)

        self._artifacts = kwargs.get('artifact', None)
        self._assignee = kwargs.get('assignee', None)
        self._case_id = kwargs.get('case_id', None)
        self._case_xid = kwargs.get('case_xid', None)
        self._completed_by = kwargs.get('completed_date', None)
        self._completed_date = kwargs.get('completed_date', None)
        self._config_playbook = kwargs.get('config_playbook', None)
        self._config_task = kwargs.get('config_task', None)
        self._dependent_on_task_name = kwargs.get('dependent_on_task_name', None)
        self._description = kwargs.get('description', None)
        self._due_date = kwargs.get('due_date', None)
        self._duration = kwargs.get('duration', None)
        self._id_dependent_on = kwargs.get('id_dependent_on', None)
        self._name = kwargs.get('name', None)
        self._notes = kwargs.get('notes', None)
        self._parent_case = kwargs.get('parent_case', None)
        self._required = kwargs.get('required', None)
        self._status = kwargs.get('status', None)
        self._workflow_phase = kwargs.get('workflow_phase', None)
        self._workflow_step = kwargs.get('workflow_step', None)
        self._xid = kwargs.get('xid', None)

    def add_note(self, **kwargs):
        """Add a note to the task"""
        self._notes.add_note(self.tcex.cm.note(**kwargs))

    @property
    def artifacts(self):
        """Return the **Artifacts** for the Task."""
        if self._artifacts:
            return self.tcex.cm.artifacts(initial_response=self._artifacts)
        return self._artifacts

    @property
    def as_entity(self):
        """Return the entity representation of the Task."""
        return {'type': 'Task', 'value': self.name, 'id': self.id}

    @property
    def assignee(self):
        """Return the **Assignee** for the Task."""
        if isinstance(self._assignee, dict):
            return self.tcex.cm.assignee(**self._assignee)
        return self._assignee

    @assignee.setter
    def assignee(self, assignee):
        """Set the **Assignee** for the Task."""
        if isinstance(assignee, dict):
            assignee = Assignee(type=assignee.get('type'), **assignee.get('data'))
        self._assignee = assignee

    @property
    def case_id(self):
        """Return the **Case ID** for the Task"""
        return self._case_id

    @case_id.setter
    def case_id(self, case_id):
        """Set the **Case ID** for the Task"""
        self._case_id = case_id

    @property
    def case_xid(self):
        """Return the **Case XID** for the Task"""
        return self._case_xid

    @case_xid.setter
    def case_xid(self, case_xid):
        """Set the **Case XID** for the Task"""
        self._case_xid = case_xid

    @property
    def completed_by(self):
        """Return the **Completed By** for the Task"""
        return self._completed_by

    @property
    def completed_date(self):
        """Return the **Completed Date** for the Task"""
        return self._completed_date

    @completed_date.setter
    def completed_date(self, completed_date):
        """Set the **Completed Date** for the Task"""
        self._completed_date = completed_date<commit_msg>minor typo in completed_by<commit_after># -*- coding: utf-8 -*-
"""ThreatConnect Task"""
from .assignee import Assignee
from .api_endpoints import ApiEndpoints
from .common_case_management import CommonCaseManagement
from .common_case_management_collection import CommonCaseManagementCollection
from .filter import Filter
from .tql import TQL


class Tasks(CommonCaseManagementCollection):
    """Tasks Class for Case Management Collection

    params example: {
        'result_limit': 100, # How many results are retrieved.
        'result_start': 10,  # Starting point on retrieved results.
        'fields': ['caseId', 'summary'] # Additional fields returned on the results
    }

    Args:
        tcex (TcEx): An instantiated instance of TcEx object.
        initial_response (dict, optional): Initial data in
            Case Object for Task. Defaults to None.
        tql_filters (list, optional): List of TQL filters. Defaults to None.
        params(dict, optional): Dict of the params to be sent while
            retrieving the Task objects.
    """

    def __init__(self, tcex, initial_response=None, tql_filters=None, params=None):
        """Initialize Class properties."""
        super().__init__(
            tcex,
            ApiEndpoints.TASKS,
            initial_response=initial_response,
            tql_filters=tql_filters,
            params=params,
        )

        if initial_response:
            for item in initial_response.get('data', []):
                self.added_items.append(Task(tcex, **item))

    def __iter__(self):
        """Object iterator"""
        return self.iterate(initial_response=self.initial_response)

    def add_task(self, task):
        """Add an task to a case.

        Args:
            task (Task): The Task Object to add.
        """
        self.added_items.append(task)

    def entity_map(self, entity):
        """Map a dict to a Task.

        Args:
            entity (dict): The Task data.

        Returns:
            CaseManagement.Task: An Task Object
        """
        return Task(self.tcex, **entity)

    @property
    def filter(self):
        """Return instance of FilterTasks Object."""
        return FilterTasks(ApiEndpoints.TASKS, self.tcex, self.tql)


class Task(CommonCaseManagement):
    """Task object for Case Management.

    Args:
        tcex (TcEx): An instantiated instance of TcEx object.
        artifacts (Artifact, kwargs): a list of Artifacts corresponding to the Task
        assignee (Assignee, kwargs): the user or group Assignee object for the Task
        case_id (int, kwargs): [Required (alt: caseXid)] The **Case Id** for the Task.
        case_xid (str, kwargs): [Required (alt: caseId)] The **Case Xid** for the Task.
        completed_by (str, kwargs): [Read-Only] The **Completed By** for the Task.
        completed_date (str, kwargs): the completion date of the Task
        config_playbook (str, kwargs): [Read-Only] The **Config Playbook** for the Task.
        config_task (dict, kwargs): [Read-Only] The **Config Task** for the Task.
        dependent_on_task_name (str, kwargs): [Read-Only] The **Dependent On Task Name** for the
            Task.
        description (str, kwargs): The **Description** for the Task.
        due_date (str, kwargs): the due date of the Task
        duration (int, kwargs): [Read-Only] The **Duration** for the Task.
        id_dependent_on (int, kwargs): [Read-Only] The **Id_Dependent On** for the Task.
        name (str, kwargs): [Required] The **Name** for the Task.
        notes (Note, kwargs): a list of Notes corresponding to the Task
        parent_case (Case, kwargs): [Read-Only] The **Parent Case** for the Task.
        required (bool, kwargs): [Read-Only] The **Required** flag for the Task.
        status (str, kwargs): The **Status** for the Task.
        workflow_phase (int, kwargs): the phase of the workflow
        workflow_step (int, kwargs): the step of the workflow
        xid (str, kwargs): The **Xid** for the Task.
    """

    def __init__(self, tcex, **kwargs):
        """Initialize Class properties"""
        super().__init__(tcex, ApiEndpoints.TASKS, kwargs)

        self._artifacts = kwargs.get('artifact', None)
        self._assignee = kwargs.get('assignee', None)
        self._case_id = kwargs.get('case_id', None)
        self._case_xid = kwargs.get('case_xid', None)
        self._completed_by = kwargs.get('completed_by', None)
        self._completed_date = kwargs.get('completed_date', None)
        self._config_playbook = kwargs.get('config_playbook', None)
        self._config_task = kwargs.get('config_task', None)
        self._dependent_on_task_name = kwargs.get('dependent_on_task_name', None)
        self._description = kwargs.get('description', None)
        self._due_date = kwargs.get('due_date', None)
        self._duration = kwargs.get('duration', None)
        self._id_dependent_on = kwargs.get('id_dependent_on', None)
        self._name = kwargs.get('name', None)
        self._notes = kwargs.get('notes', None)
        self._parent_case = kwargs.get('parent_case', None)
        self._required = kwargs.get('required', None)
        self._status = kwargs.get('status', None)
        self._workflow_phase = kwargs.get('workflow_phase', None)
        self._workflow_step = kwargs.get('workflow_step', None)
        self._xid = kwargs.get('xid', None)

    def add_note(self, **kwargs):
        """Add a note to the task"""
        self._notes.add_note(self.tcex.cm.note(**kwargs))

    @property
    def artifacts(self):
        """Return the **Artifacts** for the Task."""
        if self._artifacts:
            return self.tcex.cm.artifacts(initial_response=self._artifacts)
        return self._artifacts

    @property
    def as_entity(self):
        """Return the entity representation of the Task."""
        return {'type': 'Task', 'value': self.name, 'id': self.id}

    @property
    def assignee(self):
        """Return the **Assignee** for the Task."""
        if isinstance(self._assignee, dict):
            return self.tcex.cm.assignee(**self._assignee)
        return self._assignee

    @assignee.setter
    def assignee(self, assignee):
        """Set the **Assignee** for the Task."""
        if isinstance(assignee, dict):
            assignee = Assignee(type=assignee.get('type'), **assignee.get('data'))
        self._assignee = assignee

    @property
    def case_id(self):
        """Return the **Case ID** for the Task"""
        return self._case_id

    @case_id.setter
    def case_id(self, case_id):
        """Set the **Case ID** for the Task"""
        self._case_id = case_id

    @property
    def case_xid(self):
        """Return the **Case XID** for the Task"""
        return self._case_xid

    @case_xid.setter
    def case_xid(self, case_xid):
        """Set the **Case XID** for the Task"""
        self._case_xid = case_xid

    @property
    def completed_by(self):
        """Return the **Completed By** for the Task"""
        if self._completed_by:
            return self.tcex.cm.user(**self._completed_by)
        return self._completed_by

    @property
    def completed_date(self):
        """Return the **Completed Date** for the Task"""
        return self._completed_date

    @completed_date.setter
    def completed_date(self, completed_date):
        """Set the **Completed Date** for the Task"""
        self._completed_date = completed_date
{'fraction_non_alphanumeric': 0.11747948178796717, 'fraction_numerical': 0.000813945601302313, 'mean_word_length': 2.6980185603210436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5690867', 'n_tokens_mistral': 4327, 'n_tokens_neox': 4245, 'n_words': 1302}