# coding: utf-8

"""
    Gitea API

    This documentation describes the Gitea API.

    The version of the OpenAPI document: 1.24.5
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from py_gitea_opensuse_org.models.attachment import Attachment
from py_gitea_opensuse_org.models.label import Label
from py_gitea_opensuse_org.models.milestone import Milestone
from py_gitea_opensuse_org.models.pull_request_meta import PullRequestMeta
from py_gitea_opensuse_org.models.repository_meta import RepositoryMeta
from py_gitea_opensuse_org.models.user import User
from typing import Optional, Set
from typing_extensions import Self

class Issue(BaseModel):
    """
    Issue represents an issue in a repository
    """ # noqa: E501
    assets: Optional[List[Attachment]] = None
    assignee: Optional[User] = None
    assignees: Optional[List[User]] = None
    body: Optional[StrictStr] = None
    closed_at: Optional[datetime] = None
    comments: Optional[StrictInt] = None
    created_at: Optional[datetime] = None
    due_date: Optional[datetime] = None
    html_url: Optional[StrictStr] = None
    id: Optional[StrictInt] = None
    is_locked: Optional[StrictBool] = None
    labels: Optional[List[Label]] = None
    milestone: Optional[Milestone] = None
    number: Optional[StrictInt] = None
    original_author: Optional[StrictStr] = None
    original_author_id: Optional[StrictInt] = None
    pin_order: Optional[StrictInt] = None
    pull_request: Optional[PullRequestMeta] = None
    ref: Optional[StrictStr] = None
    repository: Optional[RepositoryMeta] = None
    state: Optional[StrictStr] = Field(default=None, description="StateType issue state type")
    title: Optional[StrictStr] = None
    updated_at: Optional[datetime] = None
    url: Optional[StrictStr] = None
    user: Optional[User] = None
    __properties: ClassVar[List[str]] = ["assets", "assignee", "assignees", "body", "closed_at", "comments", "created_at", "due_date", "html_url", "id", "is_locked", "labels", "milestone", "number", "original_author", "original_author_id", "pin_order", "pull_request", "ref", "repository", "state", "title", "updated_at", "url", "user"]

    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 Issue 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 each item in assets (list)
        _items = []
        if self.assets:
            for _item_assets in self.assets:
                if _item_assets:
                    _items.append(_item_assets.to_dict())
            _dict['assets'] = _items
        # override the default output from pydantic by calling `to_dict()` of assignee
        if self.assignee:
            _dict['assignee'] = self.assignee.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in assignees (list)
        _items = []
        if self.assignees:
            for _item_assignees in self.assignees:
                if _item_assignees:
                    _items.append(_item_assignees.to_dict())
            _dict['assignees'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in labels (list)
        _items = []
        if self.labels:
            for _item_labels in self.labels:
                if _item_labels:
                    _items.append(_item_labels.to_dict())
            _dict['labels'] = _items
        # override the default output from pydantic by calling `to_dict()` of milestone
        if self.milestone:
            _dict['milestone'] = self.milestone.to_dict()
        # override the default output from pydantic by calling `to_dict()` of pull_request
        if self.pull_request:
            _dict['pull_request'] = self.pull_request.to_dict()
        # override the default output from pydantic by calling `to_dict()` of repository
        if self.repository:
            _dict['repository'] = self.repository.to_dict()
        # override the default output from pydantic by calling `to_dict()` of user
        if self.user:
            _dict['user'] = self.user.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "assets": [Attachment.from_dict(_item) for _item in obj["assets"]] if obj.get("assets") is not None else None,
            "assignee": User.from_dict(obj["assignee"]) if obj.get("assignee") is not None else None,
            "assignees": [User.from_dict(_item) for _item in obj["assignees"]] if obj.get("assignees") is not None else None,
            "body": obj.get("body"),
            "closed_at": obj.get("closed_at"),
            "comments": obj.get("comments"),
            "created_at": obj.get("created_at"),
            "due_date": obj.get("due_date"),
            "html_url": obj.get("html_url"),
            "id": obj.get("id"),
            "is_locked": obj.get("is_locked"),
            "labels": [Label.from_dict(_item) for _item in obj["labels"]] if obj.get("labels") is not None else None,
            "milestone": Milestone.from_dict(obj["milestone"]) if obj.get("milestone") is not None else None,
            "number": obj.get("number"),
            "original_author": obj.get("original_author"),
            "original_author_id": obj.get("original_author_id"),
            "pin_order": obj.get("pin_order"),
            "pull_request": PullRequestMeta.from_dict(obj["pull_request"]) if obj.get("pull_request") is not None else None,
            "ref": obj.get("ref"),
            "repository": RepositoryMeta.from_dict(obj["repository"]) if obj.get("repository") is not None else None,
            "state": obj.get("state"),
            "title": obj.get("title"),
            "updated_at": obj.get("updated_at"),
            "url": obj.get("url"),
            "user": User.from_dict(obj["user"]) if obj.get("user") is not None else None
        })
        return _obj


