# 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.permission_permission_details_inner import PermissionPermissionDetailsInner
from google_drive_ti.models.permission_team_drive_permission_details_inner import PermissionTeamDrivePermissionDetailsInner
from typing import Optional, Set
from typing_extensions import Self

class Permission(BaseModel):
    """
    A permission for a file. A permission grants a user, group, domain, or the world access to a file or a folder hierarchy. By default, permissions requests only return a subset of fields. Permission kind, ID, type, and role are always returned. To retrieve specific fields, see https://developers.google.com/drive/api/guides/fields-parameter. Some resource methods (such as `permissions.update`) require a `permissionId`. Use the `permissions.list` method to retrieve the ID for a file, folder, or shared drive.
    """ # noqa: E501
    allow_file_discovery: Optional[StrictBool] = Field(default=None, description="Whether the permission allows the file to be discovered through search. This is only applicable for permissions of type `domain` or `anyone`.", alias="allowFileDiscovery")
    deleted: Optional[StrictBool] = Field(default=None, description="Output only. Whether the account associated with this permission has been deleted. This field only pertains to user and group permissions.")
    display_name: Optional[StrictStr] = Field(default=None, description="Output only. The \"pretty\" name of the value of the permission. The following is a list of examples for each type of permission: * `user` - User's full name, as defined for their Google account, such as \"Joe Smith.\" * `group` - Name of the Google Group, such as \"The Company Administrators.\" * `domain` - String domain name, such as \"thecompany.com.\" * `anyone` - No `displayName` is present.", alias="displayName")
    domain: Optional[StrictStr] = Field(default=None, description="The domain to which this permission refers.")
    email_address: Optional[StrictStr] = Field(default=None, description="The email address of the user or group to which this permission refers.", alias="emailAddress")
    expiration_time: Optional[datetime] = Field(default=None, description="The time at which this permission will expire (RFC 3339 date-time). Expiration times have the following restrictions: - They can only be set on user and group permissions - The time must be in the future - The time cannot be more than a year in the future", alias="expirationTime")
    id: Optional[StrictStr] = Field(default=None, description="Output only. The ID of this permission. This is a unique identifier for the grantee, and is published in User resources as `permissionId`. IDs should be treated as opaque values.")
    kind: Optional[StrictStr] = Field(default='drive#permission', description="Output only. Identifies what kind of resource this is. Value: the fixed string `\"drive#permission\"`.")
    pending_owner: Optional[StrictBool] = Field(default=None, description="Whether the account associated with this permission is a pending owner. Only populated for `user` type permissions for files that are not in a shared drive.", alias="pendingOwner")
    permission_details: Optional[List[PermissionPermissionDetailsInner]] = Field(default=None, description="Output only. Details of whether the permissions on this shared drive item are inherited or directly on this item. This is an output-only field which is present only for shared drive items.", alias="permissionDetails")
    photo_link: Optional[StrictStr] = Field(default=None, description="Output only. A link to the user's profile photo, if available.", alias="photoLink")
    role: Optional[StrictStr] = Field(default=None, description="The role granted by this permission. While new values may be supported in the future, the following are currently allowed: * `owner` * `organizer` * `fileOrganizer` * `writer` * `commenter` * `reader`")
    team_drive_permission_details: Optional[List[PermissionTeamDrivePermissionDetailsInner]] = Field(default=None, description="Output only. Deprecated: Output only. Use `permissionDetails` instead.", alias="teamDrivePermissionDetails")
    type: Optional[StrictStr] = Field(default=None, description="The type of the grantee. Valid values are: * `user` * `group` * `domain` * `anyone` When creating a permission, if `type` is `user` or `group`, you must provide an `emailAddress` for the user or group. When `type` is `domain`, you must provide a `domain`. There isn't extra information required for an `anyone` type.")
    view: Optional[StrictStr] = Field(default=None, description="Indicates the view for this permission. Only populated for permissions that belong to a view. 'published' is the only supported value.")
    __properties: ClassVar[List[str]] = ["allowFileDiscovery", "deleted", "displayName", "domain", "emailAddress", "expirationTime", "id", "kind", "pendingOwner", "permissionDetails", "photoLink", "role", "teamDrivePermissionDetails", "type", "view"]

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

        _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 permission_details (list)
        _items = []
        if self.permission_details:
            for _item_permission_details in self.permission_details:
                if _item_permission_details:
                    _items.append(_item_permission_details.to_dict())
            _dict['permissionDetails'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in team_drive_permission_details (list)
        _items = []
        if self.team_drive_permission_details:
            for _item_team_drive_permission_details in self.team_drive_permission_details:
                if _item_team_drive_permission_details:
                    _items.append(_item_team_drive_permission_details.to_dict())
            _dict['teamDrivePermissionDetails'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "allowFileDiscovery": obj.get("allowFileDiscovery"),
            "deleted": obj.get("deleted"),
            "displayName": obj.get("displayName"),
            "domain": obj.get("domain"),
            "emailAddress": obj.get("emailAddress"),
            "expirationTime": obj.get("expirationTime"),
            "id": obj.get("id"),
            "kind": obj.get("kind") if obj.get("kind") is not None else 'drive#permission',
            "pendingOwner": obj.get("pendingOwner"),
            "permissionDetails": [PermissionPermissionDetailsInner.from_dict(_item) for _item in obj["permissionDetails"]] if obj.get("permissionDetails") is not None else None,
            "photoLink": obj.get("photoLink"),
            "role": obj.get("role"),
            "teamDrivePermissionDetails": [PermissionTeamDrivePermissionDetailsInner.from_dict(_item) for _item in obj["teamDrivePermissionDetails"]] if obj.get("teamDrivePermissionDetails") is not None else None,
            "type": obj.get("type"),
            "view": obj.get("view")
        })
        return _obj


