# 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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from google_drive_ti.models.app_icons import AppIcons
from typing import Optional, Set
from typing_extensions import Self

class App(BaseModel):
    """
    The `apps` resource provides a list of apps that a user has installed, with information about each app's supported MIME types, file extensions, and other details. Some resource methods (such as `apps.get`) require an `appId`. Use the `apps.list` method to retrieve the ID for an installed application.
    """ # noqa: E501
    authorized: Optional[StrictBool] = Field(default=None, description="Whether the app is authorized to access data on the user's Drive.")
    create_in_folder_template: Optional[StrictStr] = Field(default=None, description="The template URL to create a file with this app in a given folder. The template contains the {folderId} to be replaced by the folder ID house the new file.", alias="createInFolderTemplate")
    create_url: Optional[StrictStr] = Field(default=None, description="The URL to create a file with this app.", alias="createUrl")
    has_drive_wide_scope: Optional[StrictBool] = Field(default=None, description="Whether the app has Drive-wide scope. An app with Drive-wide scope can access all files in the user's Drive.", alias="hasDriveWideScope")
    icons: Optional[List[AppIcons]] = Field(default=None, description="The various icons for the app.")
    id: Optional[StrictStr] = Field(default=None, description="The ID of the app.")
    installed: Optional[StrictBool] = Field(default=None, description="Whether the app is installed.")
    kind: Optional[StrictStr] = Field(default='drive#app', description="Output only. Identifies what kind of resource this is. Value: the fixed string \"drive#app\".")
    long_description: Optional[StrictStr] = Field(default=None, description="A long description of the app.", alias="longDescription")
    name: Optional[StrictStr] = Field(default=None, description="The name of the app.")
    object_type: Optional[StrictStr] = Field(default=None, description="The type of object this app creates such as a Chart. If empty, the app name should be used instead.", alias="objectType")
    open_url_template: Optional[StrictStr] = Field(default=None, description="The template URL for opening files with this app. The template contains {ids} or {exportIds} to be replaced by the actual file IDs. For more information, see Open Files for the full documentation.", alias="openUrlTemplate")
    primary_file_extensions: Optional[List[StrictStr]] = Field(default=None, description="The list of primary file extensions.", alias="primaryFileExtensions")
    primary_mime_types: Optional[List[StrictStr]] = Field(default=None, description="The list of primary MIME types.", alias="primaryMimeTypes")
    product_id: Optional[StrictStr] = Field(default=None, description="The ID of the product listing for this app.", alias="productId")
    product_url: Optional[StrictStr] = Field(default=None, description="A link to the product listing for this app.", alias="productUrl")
    secondary_file_extensions: Optional[List[StrictStr]] = Field(default=None, description="The list of secondary file extensions.", alias="secondaryFileExtensions")
    secondary_mime_types: Optional[List[StrictStr]] = Field(default=None, description="The list of secondary MIME types.", alias="secondaryMimeTypes")
    short_description: Optional[StrictStr] = Field(default=None, description="A short description of the app.", alias="shortDescription")
    supports_create: Optional[StrictBool] = Field(default=None, description="Whether this app supports creating objects.", alias="supportsCreate")
    supports_import: Optional[StrictBool] = Field(default=None, description="Whether this app supports importing from Google Docs.", alias="supportsImport")
    supports_multi_open: Optional[StrictBool] = Field(default=None, description="Whether this app supports opening more than one file.", alias="supportsMultiOpen")
    supports_offline_create: Optional[StrictBool] = Field(default=None, description="Whether this app supports creating files when offline.", alias="supportsOfflineCreate")
    use_by_default: Optional[StrictBool] = Field(default=None, description="Whether the app is selected as the default handler for the types it supports.", alias="useByDefault")
    __properties: ClassVar[List[str]] = ["authorized", "createInFolderTemplate", "createUrl", "hasDriveWideScope", "icons", "id", "installed", "kind", "longDescription", "name", "objectType", "openUrlTemplate", "primaryFileExtensions", "primaryMimeTypes", "productId", "productUrl", "secondaryFileExtensions", "secondaryMimeTypes", "shortDescription", "supportsCreate", "supportsImport", "supportsMultiOpen", "supportsOfflineCreate", "useByDefault"]

    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 App 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 each item in icons (list)
        _items = []
        if self.icons:
            for _item_icons in self.icons:
                if _item_icons:
                    _items.append(_item_icons.to_dict())
            _dict['icons'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "authorized": obj.get("authorized"),
            "createInFolderTemplate": obj.get("createInFolderTemplate"),
            "createUrl": obj.get("createUrl"),
            "hasDriveWideScope": obj.get("hasDriveWideScope"),
            "icons": [AppIcons.from_dict(_item) for _item in obj["icons"]] if obj.get("icons") is not None else None,
            "id": obj.get("id"),
            "installed": obj.get("installed"),
            "kind": obj.get("kind") if obj.get("kind") is not None else 'drive#app',
            "longDescription": obj.get("longDescription"),
            "name": obj.get("name"),
            "objectType": obj.get("objectType"),
            "openUrlTemplate": obj.get("openUrlTemplate"),
            "primaryFileExtensions": obj.get("primaryFileExtensions"),
            "primaryMimeTypes": obj.get("primaryMimeTypes"),
            "productId": obj.get("productId"),
            "productUrl": obj.get("productUrl"),
            "secondaryFileExtensions": obj.get("secondaryFileExtensions"),
            "secondaryMimeTypes": obj.get("secondaryMimeTypes"),
            "shortDescription": obj.get("shortDescription"),
            "supportsCreate": obj.get("supportsCreate"),
            "supportsImport": obj.get("supportsImport"),
            "supportsMultiOpen": obj.get("supportsMultiOpen"),
            "supportsOfflineCreate": obj.get("supportsOfflineCreate"),
            "useByDefault": obj.get("useByDefault")
        })
        return _obj


