# 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 ContentRestriction(BaseModel):
    """
    A restriction for accessing the content of the file.
    """ # noqa: E501
    owner_restricted: Optional[StrictBool] = Field(default=None, description="Whether the content restriction can only be modified or removed by a user who owns the file. For files in shared drives, any user with `organizer` capabilities can modify or remove this content restriction.", alias="ownerRestricted")
    read_only: Optional[StrictBool] = Field(default=None, description="Whether the content of the file is read-only. If a file is read-only, a new revision of the file may not be added, comments may not be added or modified, and the title of the file may not be modified.", alias="readOnly")
    reason: Optional[StrictStr] = Field(default=None, description="Reason for why the content of the file is restricted. This is only mutable on requests that also set `readOnly=true`.")
    restricting_user: Optional[User] = Field(default=None, alias="restrictingUser")
    restriction_time: Optional[datetime] = Field(default=None, description="The time at which the content restriction was set (formatted RFC 3339 timestamp). Only populated if readOnly is true.", alias="restrictionTime")
    system_restricted: Optional[StrictBool] = Field(default=None, description="Output only. Whether the content restriction was applied by the system, for example due to an esignature. Users cannot modify or remove system restricted content restrictions.", alias="systemRestricted")
    type: Optional[StrictStr] = Field(default=None, description="Output only. The type of the content restriction. Currently the only possible value is `globalContentRestriction`.")
    __properties: ClassVar[List[str]] = ["ownerRestricted", "readOnly", "reason", "restrictingUser", "restrictionTime", "systemRestricted", "type"]

    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 ContentRestriction 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 restricting_user
        if self.restricting_user:
            _dict['restrictingUser'] = self.restricting_user.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "ownerRestricted": obj.get("ownerRestricted"),
            "readOnly": obj.get("readOnly"),
            "reason": obj.get("reason"),
            "restrictingUser": User.from_dict(obj["restrictingUser"]) if obj.get("restrictingUser") is not None else None,
            "restrictionTime": obj.get("restrictionTime"),
            "systemRestricted": obj.get("systemRestricted"),
            "type": obj.get("type")
        })
        return _obj


