# coding: utf-8

"""
    Lumos Connectors

    # The Lumos Connector API ## Intro This API is a self-describing API which allows third-party systems to easily integrate with Lumos. It provides endpoints to retrieve information about each connector, their capabilities.  We call individual libraries that proxy Lumos requests to app-specific requests, and then app-specific responses to Lumos responses, a **connector**.  ## How to use this API 1. You can call the `list_connector_app_ids` to see the list of available connector app IDs, e.g. `pagerduty`. One app ID is required to call most other APIs. 2. Calling `info` explains * what kind of authentication credentials the integration requires * which capabilities the integration supports * what input parameters are required for each capability for the given connector  ## Authenticating with a connector There are two broad categories of authentication - Shared Secret (e.g. API keys) and OAuth-like.  TODO: explain more details - look at `info.authentication_schema` - if it's OAuth - setup needs to call - `get_authorization_url` - `handle_authorization_callback` - steady state needs to call `refresh_access_token` - `validate_credentials` will check that your creds are good, and let you know what the unique tenant ID is  ## Reading customer account data TODO: write more docs - `list_resources` - `list_entitlements` - `find_entitlement_associations`  ## Pagination TODO: write more docs - `response.page.token` may contain an opaque string - pass this string back to the next request `request.page.token` to get the next set of data

    The version of the OpenAPI document: 0.0.0
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from connector.generated.models.app_category import AppCategory
from connector.generated.models.capability_name import CapabilityName
from connector.generated.models.capability_schema import CapabilitySchema
from connector.generated.models.entitlement_type import EntitlementType
from connector.generated.models.resource_type import ResourceType
from typing import Optional, Set
from typing_extensions import Self

class Info(BaseModel):
    """
    Info
    """ # noqa: E501
    app_id: StrictStr = Field(description="A unique ID for this integration, that computers read.")
    capabilities: List[CapabilityName] = Field(description="All capabilities provided by this integration.")
    capability_schema: Dict[str, CapabilitySchema] = Field(description="A map of capability names to schemas (how to call them, what they return)")
    authentication_schema: Dict[str, Any] = Field(description="A JSON schema for the \"auth\" field on requests.")
    logo_url: Optional[StrictStr] = Field(default=None, description="A fully qualified URL to an image with this integration's logo.")
    user_friendly_name: Optional[StrictStr] = Field(default=None, description="The name of the app this is integrating with.")
    description: Optional[StrictStr] = Field(default=None, description="1-3 sentences describing the product/service the app provides")
    categories: Optional[List[AppCategory]] = None
    entitlement_types: List[EntitlementType] = Field(description="A list of entitlement types supported by this connector.")
    resource_types: List[ResourceType] = Field(description="A list of resource types supported by this connector.")
    request_settings_schema: Dict[str, Any] = Field(description="A JSON schema that tells clients how to send request.settings for this app.")
    __properties: ClassVar[List[str]] = ["app_id", "capabilities", "capability_schema", "authentication_schema", "logo_url", "user_friendly_name", "description", "categories", "entitlement_types", "resource_types", "request_settings_schema"]

    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 Info 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 value in capability_schema (dict)
        _field_dict = {}
        if self.capability_schema:
            for _key_capability_schema in self.capability_schema:
                if self.capability_schema[_key_capability_schema]:
                    _field_dict[_key_capability_schema] = self.capability_schema[_key_capability_schema].to_dict()
            _dict['capability_schema'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each item in entitlement_types (list)
        _items = []
        if self.entitlement_types:
            for _item_entitlement_types in self.entitlement_types:
                if _item_entitlement_types:
                    _items.append(_item_entitlement_types.to_dict())
            _dict['entitlement_types'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in resource_types (list)
        _items = []
        if self.resource_types:
            for _item_resource_types in self.resource_types:
                if _item_resource_types:
                    _items.append(_item_resource_types.to_dict())
            _dict['resource_types'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "app_id": obj.get("app_id"),
            "capabilities": obj.get("capabilities"),
            "capability_schema": dict(
                (_k, CapabilitySchema.from_dict(_v))
                for _k, _v in obj["capability_schema"].items()
            )
            if obj.get("capability_schema") is not None
            else None,
            "authentication_schema": obj.get("authentication_schema"),
            "logo_url": obj.get("logo_url"),
            "user_friendly_name": obj.get("user_friendly_name"),
            "description": obj.get("description"),
            "categories": obj.get("categories"),
            "entitlement_types": [EntitlementType.from_dict(_item) for _item in obj["entitlement_types"]] if obj.get("entitlement_types") is not None else None,
            "resource_types": [ResourceType.from_dict(_item) for _item in obj["resource_types"]] if obj.get("resource_types") is not None else None,
            "request_settings_schema": obj.get("request_settings_schema")
        })
        return _obj


