# coding: utf-8

"""
    The Jira Cloud platform REST API

    Jira Cloud platform REST API documentation

    The version of the OpenAPI document: 1001.0.0-SNAPSHOT-7ce0ee67a52d004425175cea962ad1c1c7200181
    Contact: ecosystem@atlassian.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from jira_client.models.project_issue_types import ProjectIssueTypes
from jira_client.models.status_scope import StatusScope
from jira_client.models.workflow_usages import WorkflowUsages
from typing import Optional, Set
from typing_extensions import Self

class JiraStatus(BaseModel):
    """
    Details of a status.
    """ # noqa: E501
    description: Optional[StrictStr] = Field(default=None, description="The description of the status.")
    id: Optional[StrictStr] = Field(default=None, description="The ID of the status.")
    name: Optional[StrictStr] = Field(default=None, description="The name of the status.")
    scope: Optional[StatusScope] = None
    status_category: Optional[StrictStr] = Field(default=None, description="The category of the status.", alias="statusCategory")
    usages: Optional[List[Optional[ProjectIssueTypes]]] = Field(default=None, description="Deprecated. See the [deprecation notice](https://developer.atlassian.com/cloud/jira/platform/changelog/#CHANGE-2298) for details.  Projects and issue types where the status is used. Only available if the `usages` expand is requested.")
    workflow_usages: Optional[List[Optional[WorkflowUsages]]] = Field(default=None, description="Deprecated. See the [deprecation notice](https://developer.atlassian.com/cloud/jira/platform/changelog/#CHANGE-2298) for details.  The workflows that use this status. Only available if the `workflowUsages` expand is requested.", alias="workflowUsages")
    __properties: ClassVar[List[str]] = ["description", "id", "name", "scope", "statusCategory", "usages", "workflowUsages"]

    @field_validator('status_category')
    def status_category_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['TODO', 'IN_PROGRESS', 'DONE']):
            raise ValueError("must be one of enum values ('TODO', 'IN_PROGRESS', 'DONE')")
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of JiraStatus from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of scope
        if self.scope:
            _dict['scope'] = self.scope.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in usages (list)
        _items = []
        if self.usages:
            for _item_usages in self.usages:
                if _item_usages:
                    _items.append(_item_usages.to_dict())
            _dict['usages'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in workflow_usages (list)
        _items = []
        if self.workflow_usages:
            for _item_workflow_usages in self.workflow_usages:
                if _item_workflow_usages:
                    _items.append(_item_workflow_usages.to_dict())
            _dict['workflowUsages'] = _items
        # set to None if usages (nullable) is None
        # and model_fields_set contains the field
        if self.usages is None and "usages" in self.model_fields_set:
            _dict['usages'] = None

        # set to None if workflow_usages (nullable) is None
        # and model_fields_set contains the field
        if self.workflow_usages is None and "workflow_usages" in self.model_fields_set:
            _dict['workflowUsages'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of JiraStatus from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "description": obj.get("description"),
            "id": obj.get("id"),
            "name": obj.get("name"),
            "scope": StatusScope.from_dict(obj["scope"]) if obj.get("scope") is not None else None,
            "statusCategory": obj.get("statusCategory"),
            "usages": [ProjectIssueTypes.from_dict(_item) for _item in obj["usages"]] if obj.get("usages") is not None else None,
            "workflowUsages": [WorkflowUsages.from_dict(_item) for _item in obj["workflowUsages"]] if obj.get("workflowUsages") is not None else None
        })
        return _obj


