# 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.content_restriction import ContentRestriction
from google_drive_ti.models.file_capabilities import FileCapabilities
from google_drive_ti.models.file_content_hints import FileContentHints
from google_drive_ti.models.file_image_media_metadata import FileImageMediaMetadata
from google_drive_ti.models.file_label_info import FileLabelInfo
from google_drive_ti.models.file_link_share_metadata import FileLinkShareMetadata
from google_drive_ti.models.file_shortcut_details import FileShortcutDetails
from google_drive_ti.models.file_video_media_metadata import FileVideoMediaMetadata
from google_drive_ti.models.permission import Permission
from google_drive_ti.models.user import User
from typing import Optional, Set
from typing_extensions import Self

class File(BaseModel):
    """
    The metadata for a file. Some resource methods (such as `files.update`) require a `fileId`. Use the `files.list` method to retrieve the ID for a file.
    """ # noqa: E501
    app_properties: Optional[Dict[str, Any]] = Field(default=None, description="A collection of arbitrary key-value pairs which are private to the requesting app. Entries with null values are cleared in update and copy requests. These properties can only be retrieved using an authenticated request. An authenticated request uses an access token obtained with a OAuth 2 client ID. You cannot use an API key to retrieve private properties.", alias="appProperties")
    capabilities: Optional[FileCapabilities] = None
    content_hints: Optional[FileContentHints] = Field(default=None, alias="contentHints")
    content_restrictions: Optional[List[ContentRestriction]] = Field(default=None, description="Restrictions for accessing the content of the file. Only populated if such a restriction exists.", alias="contentRestrictions")
    copy_requires_writer_permission: Optional[StrictBool] = Field(default=None, description="Whether the options to copy, print, or download this file, should be disabled for readers and commenters.", alias="copyRequiresWriterPermission")
    created_time: Optional[datetime] = Field(default=None, description="The time at which the file was created (RFC 3339 date-time).", alias="createdTime")
    description: Optional[StrictStr] = Field(default=None, description="A short description of the file.")
    drive_id: Optional[StrictStr] = Field(default=None, description="Output only. ID of the shared drive the file resides in. Only populated for items in shared drives.", alias="driveId")
    explicitly_trashed: Optional[StrictBool] = Field(default=None, description="Output only. Whether the file has been explicitly trashed, as opposed to recursively trashed from a parent folder.", alias="explicitlyTrashed")
    export_links: Optional[Dict[str, Any]] = Field(default=None, description="Output only. Links for exporting Docs Editors files to specific formats.", alias="exportLinks")
    file_extension: Optional[StrictStr] = Field(default=None, description="Output only. The final component of `fullFileExtension`. This is only available for files with binary content in Google Drive.", alias="fileExtension")
    folder_color_rgb: Optional[StrictStr] = Field(default=None, description="The color for a folder or a shortcut to a folder as an RGB hex string. The supported colors are published in the `folderColorPalette` field of the About resource. If an unsupported color is specified, the closest color in the palette is used instead.", alias="folderColorRgb")
    full_file_extension: Optional[StrictStr] = Field(default=None, description="Output only. The full file extension extracted from the `name` field. May contain multiple concatenated extensions, such as \"tar.gz\". This is only available for files with binary content in Google Drive. This is automatically updated when the `name` field changes, however it is not cleared if the new name does not contain a valid extension.", alias="fullFileExtension")
    has_augmented_permissions: Optional[StrictBool] = Field(default=None, description="Output only. Whether there are permissions directly on this file. This field is only populated for items in shared drives.", alias="hasAugmentedPermissions")
    has_thumbnail: Optional[StrictBool] = Field(default=None, description="Output only. Whether this file has a thumbnail. This does not indicate whether the requesting app has access to the thumbnail. To check access, look for the presence of the thumbnailLink field.", alias="hasThumbnail")
    head_revision_id: Optional[StrictStr] = Field(default=None, description="Output only. The ID of the file's head revision. This is currently only available for files with binary content in Google Drive.", alias="headRevisionId")
    icon_link: Optional[StrictStr] = Field(default=None, description="Output only. A static, unauthenticated link to the file's icon.", alias="iconLink")
    id: Optional[StrictStr] = Field(default=None, description="The ID of the file.")
    image_media_metadata: Optional[FileImageMediaMetadata] = Field(default=None, alias="imageMediaMetadata")
    is_app_authorized: Optional[StrictBool] = Field(default=None, description="Output only. Whether the file was created or opened by the requesting app.", alias="isAppAuthorized")
    kind: Optional[StrictStr] = Field(default='drive#file', description="Output only. Identifies what kind of resource this is. Value: the fixed string `\"drive#file\"`.")
    label_info: Optional[FileLabelInfo] = Field(default=None, alias="labelInfo")
    last_modifying_user: Optional[User] = Field(default=None, alias="lastModifyingUser")
    link_share_metadata: Optional[FileLinkShareMetadata] = Field(default=None, alias="linkShareMetadata")
    md5_checksum: Optional[StrictStr] = Field(default=None, description="Output only. The MD5 checksum for the content of the file. This is only applicable to files with binary content in Google Drive.", alias="md5Checksum")
    mime_type: Optional[StrictStr] = Field(default=None, description="The MIME type of the file. Google Drive attempts to automatically detect an appropriate value from uploaded content, if no value is provided. The value cannot be changed unless a new revision is uploaded. If a file is created with a Google Doc MIME type, the uploaded content is imported, if possible. The supported import formats are published in the About resource.", alias="mimeType")
    modified_by_me: Optional[StrictBool] = Field(default=None, description="Output only. Whether the file has been modified by this user.", alias="modifiedByMe")
    modified_by_me_time: Optional[datetime] = Field(default=None, description="The last time the file was modified by the user (RFC 3339 date-time).", alias="modifiedByMeTime")
    modified_time: Optional[datetime] = Field(default=None, description="he last time the file was modified by anyone (RFC 3339 date-time). Note that setting modifiedTime will also update modifiedByMeTime for the user.", alias="modifiedTime")
    name: Optional[StrictStr] = Field(default=None, description="The name of the file. This is not necessarily unique within a folder. Note that for immutable items such as the top level folders of shared drives, My Drive root folder, and Application Data folder the name is constant.")
    original_filename: Optional[StrictStr] = Field(default=None, description="The original filename of the uploaded content if available, or else the original value of the `name` field. This is only available for files with binary content in Google Drive.", alias="originalFilename")
    owned_by_me: Optional[StrictBool] = Field(default=None, description="Output only. Whether the user owns the file. Not populated for items in shared drives.", alias="ownedByMe")
    owners: Optional[List[User]] = Field(default=None, description="Output only. The owner of this file. Only certain legacy files may have more than one owner. This field isn't populated for items in shared drives.")
    parents: Optional[List[StrictStr]] = Field(default=None, description="The ID of the parent folder containing the file. A file can only have one parent folder; specifying multiple parents isn't supported. If not specified as part of a create request, the file is placed directly in the user's My Drive folder. If not specified as part of a copy request, the file inherits any discoverable parent of the source file. Update requests must use the `addParents` and `removeParents` parameters to modify the parents list.")
    permission_ids: Optional[List[StrictStr]] = Field(default=None, description="Output only. List of permission IDs for users with access to this file.", alias="permissionIds")
    permissions: Optional[List[Permission]] = Field(default=None, description="Output only. The full list of permissions for the file. This is only available if the requesting user can share the file. Not populated for items in shared drives.")
    properties: Optional[Dict[str, Any]] = Field(default=None, description="A collection of arbitrary key-value pairs which are visible to all apps. Entries with null values are cleared in update and copy requests.")
    quota_bytes_used: Optional[StrictStr] = Field(default=None, description="Output only. The number of storage quota bytes used by the file. This includes the head revision as well as previous revisions with `keepForever` enabled.", alias="quotaBytesUsed")
    resource_key: Optional[StrictStr] = Field(default=None, description="Output only. A key needed to access the item via a shared link.", alias="resourceKey")
    sha1_checksum: Optional[StrictStr] = Field(default=None, description="Output only. The SHA1 checksum associated with this file, if available. This field is only populated for files with content stored in Google Drive; it is not populated for Docs Editors or shortcut files.", alias="sha1Checksum")
    sha256_checksum: Optional[StrictStr] = Field(default=None, description="Output only. The SHA256 checksum associated with this file, if available. This field is only populated for files with content stored in Google Drive; it is not populated for Docs Editors or shortcut files.", alias="sha256Checksum")
    shared: Optional[StrictBool] = Field(default=None, description="Output only. Whether the file has been shared. Not populated for items in shared drives.")
    shared_with_me_time: Optional[datetime] = Field(default=None, description="The time at which the file was shared with the user, if applicable (RFC 3339 date-time).", alias="sharedWithMeTime")
    sharing_user: Optional[User] = Field(default=None, alias="sharingUser")
    shortcut_details: Optional[FileShortcutDetails] = Field(default=None, alias="shortcutDetails")
    size: Optional[StrictStr] = Field(default=None, description="Output only. Size in bytes of blobs and first party editor files. Won't be populated for files that have no size, like shortcuts and folders.")
    spaces: Optional[List[StrictStr]] = Field(default=None, description="Output only. The list of spaces which contain the file. The currently supported values are 'drive', 'appDataFolder' and 'photos'.")
    starred: Optional[StrictBool] = Field(default=None, description="Whether the user has starred the file.")
    team_drive_id: Optional[StrictStr] = Field(default=None, description="Deprecated: Output only. Use `driveId` instead.", alias="teamDriveId")
    thumbnail_link: Optional[StrictStr] = Field(default=None, description="Output only. A short-lived link to the file's thumbnail, if available. Typically lasts on the order of hours. Not intended for direct usage on web applications due to [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) policies, consider using a proxy server. Only populated when the requesting app can access the file's content. If the file isn't shared publicly, the URL returned in `Files.thumbnailLink` must be fetched using a credentialed request.", alias="thumbnailLink")
    thumbnail_version: Optional[StrictStr] = Field(default=None, description="Output only. The thumbnail version for use in thumbnail cache invalidation.", alias="thumbnailVersion")
    trashed: Optional[StrictBool] = Field(default=None, description="Whether the file has been trashed, either explicitly or from a trashed parent folder. Only the owner may trash a file, and other users cannot see files in the owner's trash.")
    trashed_time: Optional[datetime] = Field(default=None, description="The time that the item was trashed (RFC 3339 date-time). Only populated for items in shared drives.", alias="trashedTime")
    trashing_user: Optional[User] = Field(default=None, alias="trashingUser")
    version: Optional[StrictStr] = Field(default=None, description="Output only. A monotonically increasing version number for the file. This reflects every change made to the file on the server, even those not visible to the user.")
    video_media_metadata: Optional[FileVideoMediaMetadata] = Field(default=None, alias="videoMediaMetadata")
    viewed_by_me: Optional[StrictBool] = Field(default=None, description="Output only. Whether the file has been viewed by this user.", alias="viewedByMe")
    viewed_by_me_time: Optional[datetime] = Field(default=None, description="The last time the file was viewed by the user (RFC 3339 date-time).", alias="viewedByMeTime")
    viewers_can_copy_content: Optional[StrictBool] = Field(default=None, description="Deprecated: Use `copyRequiresWriterPermission` instead.", alias="viewersCanCopyContent")
    web_content_link: Optional[StrictStr] = Field(default=None, description="Output only. A link for downloading the content of the file in a browser. This is only available for files with binary content in Google Drive.", alias="webContentLink")
    web_view_link: Optional[StrictStr] = Field(default=None, description="Output only. A link for opening the file in a relevant Google editor or viewer in a browser.", alias="webViewLink")
    writers_can_share: Optional[StrictBool] = Field(default=None, description="Whether users with only `writer` permission can modify the file's permissions. Not populated for items in shared drives.", alias="writersCanShare")
    __properties: ClassVar[List[str]] = ["appProperties", "capabilities", "contentHints", "contentRestrictions", "copyRequiresWriterPermission", "createdTime", "description", "driveId", "explicitlyTrashed", "exportLinks", "fileExtension", "folderColorRgb", "fullFileExtension", "hasAugmentedPermissions", "hasThumbnail", "headRevisionId", "iconLink", "id", "imageMediaMetadata", "isAppAuthorized", "kind", "labelInfo", "lastModifyingUser", "linkShareMetadata", "md5Checksum", "mimeType", "modifiedByMe", "modifiedByMeTime", "modifiedTime", "name", "originalFilename", "ownedByMe", "owners", "parents", "permissionIds", "permissions", "properties", "quotaBytesUsed", "resourceKey", "sha1Checksum", "sha256Checksum", "shared", "sharedWithMeTime", "sharingUser", "shortcutDetails", "size", "spaces", "starred", "teamDriveId", "thumbnailLink", "thumbnailVersion", "trashed", "trashedTime", "trashingUser", "version", "videoMediaMetadata", "viewedByMe", "viewedByMeTime", "viewersCanCopyContent", "webContentLink", "webViewLink", "writersCanShare"]

    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 File 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.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "export_links",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of capabilities
        if self.capabilities:
            _dict['capabilities'] = self.capabilities.to_dict()
        # override the default output from pydantic by calling `to_dict()` of content_hints
        if self.content_hints:
            _dict['contentHints'] = self.content_hints.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in content_restrictions (list)
        _items = []
        if self.content_restrictions:
            for _item_content_restrictions in self.content_restrictions:
                if _item_content_restrictions:
                    _items.append(_item_content_restrictions.to_dict())
            _dict['contentRestrictions'] = _items
        # override the default output from pydantic by calling `to_dict()` of image_media_metadata
        if self.image_media_metadata:
            _dict['imageMediaMetadata'] = self.image_media_metadata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of label_info
        if self.label_info:
            _dict['labelInfo'] = self.label_info.to_dict()
        # 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()
        # override the default output from pydantic by calling `to_dict()` of link_share_metadata
        if self.link_share_metadata:
            _dict['linkShareMetadata'] = self.link_share_metadata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in owners (list)
        _items = []
        if self.owners:
            for _item_owners in self.owners:
                if _item_owners:
                    _items.append(_item_owners.to_dict())
            _dict['owners'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in permissions (list)
        _items = []
        if self.permissions:
            for _item_permissions in self.permissions:
                if _item_permissions:
                    _items.append(_item_permissions.to_dict())
            _dict['permissions'] = _items
        # override the default output from pydantic by calling `to_dict()` of sharing_user
        if self.sharing_user:
            _dict['sharingUser'] = self.sharing_user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of shortcut_details
        if self.shortcut_details:
            _dict['shortcutDetails'] = self.shortcut_details.to_dict()
        # override the default output from pydantic by calling `to_dict()` of trashing_user
        if self.trashing_user:
            _dict['trashingUser'] = self.trashing_user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of video_media_metadata
        if self.video_media_metadata:
            _dict['videoMediaMetadata'] = self.video_media_metadata.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "appProperties": obj.get("appProperties"),
            "capabilities": FileCapabilities.from_dict(obj["capabilities"]) if obj.get("capabilities") is not None else None,
            "contentHints": FileContentHints.from_dict(obj["contentHints"]) if obj.get("contentHints") is not None else None,
            "contentRestrictions": [ContentRestriction.from_dict(_item) for _item in obj["contentRestrictions"]] if obj.get("contentRestrictions") is not None else None,
            "copyRequiresWriterPermission": obj.get("copyRequiresWriterPermission"),
            "createdTime": obj.get("createdTime"),
            "description": obj.get("description"),
            "driveId": obj.get("driveId"),
            "explicitlyTrashed": obj.get("explicitlyTrashed"),
            "exportLinks": obj.get("exportLinks"),
            "fileExtension": obj.get("fileExtension"),
            "folderColorRgb": obj.get("folderColorRgb"),
            "fullFileExtension": obj.get("fullFileExtension"),
            "hasAugmentedPermissions": obj.get("hasAugmentedPermissions"),
            "hasThumbnail": obj.get("hasThumbnail"),
            "headRevisionId": obj.get("headRevisionId"),
            "iconLink": obj.get("iconLink"),
            "id": obj.get("id"),
            "imageMediaMetadata": FileImageMediaMetadata.from_dict(obj["imageMediaMetadata"]) if obj.get("imageMediaMetadata") is not None else None,
            "isAppAuthorized": obj.get("isAppAuthorized"),
            "kind": obj.get("kind") if obj.get("kind") is not None else 'drive#file',
            "labelInfo": FileLabelInfo.from_dict(obj["labelInfo"]) if obj.get("labelInfo") is not None else None,
            "lastModifyingUser": User.from_dict(obj["lastModifyingUser"]) if obj.get("lastModifyingUser") is not None else None,
            "linkShareMetadata": FileLinkShareMetadata.from_dict(obj["linkShareMetadata"]) if obj.get("linkShareMetadata") is not None else None,
            "md5Checksum": obj.get("md5Checksum"),
            "mimeType": obj.get("mimeType"),
            "modifiedByMe": obj.get("modifiedByMe"),
            "modifiedByMeTime": obj.get("modifiedByMeTime"),
            "modifiedTime": obj.get("modifiedTime"),
            "name": obj.get("name"),
            "originalFilename": obj.get("originalFilename"),
            "ownedByMe": obj.get("ownedByMe"),
            "owners": [User.from_dict(_item) for _item in obj["owners"]] if obj.get("owners") is not None else None,
            "parents": obj.get("parents"),
            "permissionIds": obj.get("permissionIds"),
            "permissions": [Permission.from_dict(_item) for _item in obj["permissions"]] if obj.get("permissions") is not None else None,
            "properties": obj.get("properties"),
            "quotaBytesUsed": obj.get("quotaBytesUsed"),
            "resourceKey": obj.get("resourceKey"),
            "sha1Checksum": obj.get("sha1Checksum"),
            "sha256Checksum": obj.get("sha256Checksum"),
            "shared": obj.get("shared"),
            "sharedWithMeTime": obj.get("sharedWithMeTime"),
            "sharingUser": User.from_dict(obj["sharingUser"]) if obj.get("sharingUser") is not None else None,
            "shortcutDetails": FileShortcutDetails.from_dict(obj["shortcutDetails"]) if obj.get("shortcutDetails") is not None else None,
            "size": obj.get("size"),
            "spaces": obj.get("spaces"),
            "starred": obj.get("starred"),
            "teamDriveId": obj.get("teamDriveId"),
            "thumbnailLink": obj.get("thumbnailLink"),
            "thumbnailVersion": obj.get("thumbnailVersion"),
            "trashed": obj.get("trashed"),
            "trashedTime": obj.get("trashedTime"),
            "trashingUser": User.from_dict(obj["trashingUser"]) if obj.get("trashingUser") is not None else None,
            "version": obj.get("version"),
            "videoMediaMetadata": FileVideoMediaMetadata.from_dict(obj["videoMediaMetadata"]) if obj.get("videoMediaMetadata") is not None else None,
            "viewedByMe": obj.get("viewedByMe"),
            "viewedByMeTime": obj.get("viewedByMeTime"),
            "viewersCanCopyContent": obj.get("viewersCanCopyContent"),
            "webContentLink": obj.get("webContentLink"),
            "webViewLink": obj.get("webViewLink"),
            "writersCanShare": obj.get("writersCanShare")
        })
        return _obj


