# 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.workflow_scope import WorkflowScope
from typing import Optional, Set
from typing_extensions import Self

class JiraWorkflowStatus(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[WorkflowScope] = None
    status_category: Optional[StrictStr] = Field(default=None, description="The category of the status.", alias="statusCategory")
    status_reference: Optional[StrictStr] = Field(default=None, description="The reference of the status.", alias="statusReference")
    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.  The `statuses.usages` expand is an optional parameter that can be used when reading and updating statuses in Jira. It provides additional information about the projects and issue types associated with the requested statuses.")
    __properties: ClassVar[List[str]] = ["description", "id", "name", "scope", "statusCategory", "statusReference", "usages"]

    @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 JiraWorkflowStatus 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
        # 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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of JiraWorkflowStatus 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": WorkflowScope.from_dict(obj["scope"]) if obj.get("scope") is not None else None,
            "statusCategory": obj.get("statusCategory"),
            "statusReference": obj.get("statusReference"),
            "usages": [ProjectIssueTypes.from_dict(_item) for _item in obj["usages"]] if obj.get("usages") is not None else None
        })
        return _obj


