# coding: utf-8

"""
    Gitea API

    This documentation describes the Gitea API.

    The version of the OpenAPI document: 1.21.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 pydantic import BaseModel, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from py_gitea_opensuse_org.models.file_links_response import FileLinksResponse
from typing import Optional, Set
from typing_extensions import Self

class ContentsResponse(BaseModel):
    """
    ContentsResponse contains information about a repo's entry's (dir, file, symlink, submodule) metadata and content
    """ # noqa: E501
    links: Optional[FileLinksResponse] = Field(default=None, alias="_links")
    content: Optional[StrictStr] = Field(default=None, description="`content` is populated when `type` is `file`, otherwise null")
    download_url: Optional[StrictStr] = None
    encoding: Optional[StrictStr] = Field(default=None, description="`encoding` is populated when `type` is `file`, otherwise null")
    git_url: Optional[StrictStr] = None
    html_url: Optional[StrictStr] = None
    last_commit_sha: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    path: Optional[StrictStr] = None
    sha: Optional[StrictStr] = None
    size: Optional[StrictInt] = None
    submodule_git_url: Optional[StrictStr] = Field(default=None, description="`submodule_git_url` is populated when `type` is `submodule`, otherwise null")
    target: Optional[StrictStr] = Field(default=None, description="`target` is populated when `type` is `symlink`, otherwise null")
    type: Optional[StrictStr] = Field(default=None, description="`type` will be `file`, `dir`, `symlink`, or `submodule`")
    url: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["_links", "content", "download_url", "encoding", "git_url", "html_url", "last_commit_sha", "name", "path", "sha", "size", "submodule_git_url", "target", "type", "url"]

    model_config = {
        "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 ContentsResponse 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 links
        if self.links:
            _dict['_links'] = self.links.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "_links": FileLinksResponse.from_dict(obj["_links"]) if obj.get("_links") is not None else None,
            "content": obj.get("content"),
            "download_url": obj.get("download_url"),
            "encoding": obj.get("encoding"),
            "git_url": obj.get("git_url"),
            "html_url": obj.get("html_url"),
            "last_commit_sha": obj.get("last_commit_sha"),
            "name": obj.get("name"),
            "path": obj.get("path"),
            "sha": obj.get("sha"),
            "size": obj.get("size"),
            "submodule_git_url": obj.get("submodule_git_url"),
            "target": obj.get("target"),
            "type": obj.get("type"),
            "url": obj.get("url")
        })
        return _obj


