# coding: utf-8

"""
    Gitea API.

    This documentation describes the Gitea API.

    The version of the OpenAPI document: 1.19.4
    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 typing import Optional
from pydantic import BaseModel, Field, StrictInt, StrictStr
from py_gitea_opensuse_org.models.user import User

class CommitStatus(BaseModel):
    """
    CommitStatus holds a single status of a single Commit
    """
    context: Optional[StrictStr] = None
    created_at: Optional[datetime] = None
    creator: Optional[User] = None
    description: Optional[StrictStr] = None
    id: Optional[StrictInt] = None
    status: Optional[StrictStr] = Field(None, description="CommitStatusState holds the state of a CommitStatus It can be \"pending\", \"success\", \"error\", \"failure\", and \"warning\"")
    target_url: Optional[StrictStr] = None
    updated_at: Optional[datetime] = None
    url: Optional[StrictStr] = None
    __properties = ["context", "created_at", "creator", "description", "id", "status", "target_url", "updated_at", "url"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

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

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

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

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of creator
        if self.creator:
            _dict['creator'] = self.creator.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> CommitStatus:
        """Create an instance of CommitStatus from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return CommitStatus.parse_obj(obj)

        _obj = CommitStatus.parse_obj({
            "context": obj.get("context"),
            "created_at": obj.get("created_at"),
            "creator": User.from_dict(obj.get("creator")) if obj.get("creator") is not None else None,
            "description": obj.get("description"),
            "id": obj.get("id"),
            "status": obj.get("status"),
            "target_url": obj.get("target_url"),
            "updated_at": obj.get("updated_at"),
            "url": obj.get("url")
        })
        return _obj


