# coding: utf-8

"""
    Google Drive API

    The Google Drive API allows clients to access resources from Google Drive.

    The version of the OpenAPI document: v3
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from google_drive_ti.models.user import User
from typing import Optional, Set
from typing_extensions import Self

class Revision(BaseModel):
    """
    The metadata for a revision to a file. Some resource methods (such as `revisions.update`) require a `revisionId`. Use the `revisions.list` method to retrieve the ID for a revision.
    """ # noqa: E501
    export_links: Optional[Dict[str, Any]] = Field(default=None, description="Output only. Links for exporting Docs Editors files to specific formats.", alias="exportLinks")
    id: Optional[StrictStr] = Field(default=None, description="Output only. The ID of the revision.")
    keep_forever: Optional[StrictBool] = Field(default=None, description="Whether to keep this revision forever, even if it is no longer the head revision. If not set, the revision will be automatically purged 30 days after newer content is uploaded. This can be set on a maximum of 200 revisions for a file. This field is only applicable to files with binary content in Drive.", alias="keepForever")
    kind: Optional[StrictStr] = Field(default='drive#revision', description="Output only. Identifies what kind of resource this is. Value: the fixed string `\"drive#revision\"`.")
    last_modifying_user: Optional[User] = Field(default=None, alias="lastModifyingUser")
    md5_checksum: Optional[StrictStr] = Field(default=None, description="Output only. The MD5 checksum of the revision's content. This is only applicable to files with binary content in Drive.", alias="md5Checksum")
    mime_type: Optional[StrictStr] = Field(default=None, description="Output only. The MIME type of the revision.", alias="mimeType")
    modified_time: Optional[datetime] = Field(default=None, description="The last time the revision was modified (RFC 3339 date-time).", alias="modifiedTime")
    original_filename: Optional[StrictStr] = Field(default=None, description="Output only. The original filename used to create this revision. This is only applicable to files with binary content in Drive.", alias="originalFilename")
    publish_auto: Optional[StrictBool] = Field(default=None, description="Whether subsequent revisions will be automatically republished. This is only applicable to Docs Editors files.", alias="publishAuto")
    published: Optional[StrictBool] = Field(default=None, description="Whether this revision is published. This is only applicable to Docs Editors files.")
    published_link: Optional[StrictStr] = Field(default=None, description="Output only. A link to the published revision. This is only populated for Docs Editors files.", alias="publishedLink")
    published_outside_domain: Optional[StrictBool] = Field(default=None, description="Whether this revision is published outside the domain. This is only applicable to Docs Editors files.", alias="publishedOutsideDomain")
    size: Optional[StrictStr] = Field(default=None, description="Output only. The size of the revision's content in bytes. This is only applicable to files with binary content in Drive.")
    __properties: ClassVar[List[str]] = ["exportLinks", "id", "keepForever", "kind", "lastModifyingUser", "md5Checksum", "mimeType", "modifiedTime", "originalFilename", "publishAuto", "published", "publishedLink", "publishedOutsideDomain", "size"]

    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 Revision 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 last_modifying_user
        if self.last_modifying_user:
            _dict['lastModifyingUser'] = self.last_modifying_user.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "exportLinks": obj.get("exportLinks"),
            "id": obj.get("id"),
            "keepForever": obj.get("keepForever"),
            "kind": obj.get("kind") if obj.get("kind") is not None else 'drive#revision',
            "lastModifyingUser": User.from_dict(obj["lastModifyingUser"]) if obj.get("lastModifyingUser") is not None else None,
            "md5Checksum": obj.get("md5Checksum"),
            "mimeType": obj.get("mimeType"),
            "modifiedTime": obj.get("modifiedTime"),
            "originalFilename": obj.get("originalFilename"),
            "publishAuto": obj.get("publishAuto"),
            "published": obj.get("published"),
            "publishedLink": obj.get("publishedLink"),
            "publishedOutsideDomain": obj.get("publishedOutsideDomain"),
            "size": obj.get("size")
        })
        return _obj


