# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 4.202.1-ai-plus
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from uuid import UUID
from iblai.models.auth_scope_enum import AuthScopeEnum
from iblai.models.auth_type_enum import AuthTypeEnum
from iblai.models.o_auth_service import OAuthService
from iblai.models.transport_enum import TransportEnum
from typing import Optional, Set
from typing_extensions import Self

class MCPServer(BaseModel):
    """
    Serializer for the MCPServer model.
    """ # noqa: E501
    id: StrictInt
    platform: StrictInt
    mentor: Optional[UUID] = None
    owner: Optional[StrictStr] = Field(default=None, description="edX username")
    name: Annotated[str, Field(strict=True, max_length=255)]
    description: Optional[StrictStr] = Field(default=None, description="A description of the MCP server.")
    url: Annotated[str, Field(strict=True, max_length=200)] = Field(description="The url of the MCP server.")
    image: Optional[StrictStr] = None
    transport: Optional[TransportEnum] = None
    credentials: Optional[StrictStr] = Field(default=None, description="Authorization credentials to authenticate to the MCP server. If provided, these take priority over any headers configured on the server. Token here must be the full authorization value. For example: `<scheme> <credentials>`")
    extra_headers: Optional[Any] = Field(default=None, description="Headers to send to the MCP server. Useful for authentication,")
    platform_key: StrictStr
    is_featured: Optional[StrictBool] = Field(default=None, description="Featured mcp servers will be accessible to all other tenants.")
    auth_type: Optional[AuthTypeEnum] = Field(default=None, description="The type of authentication to use for the MCP server.  * `none` - None * `token` - Token * `oauth2` - Oauth2")
    auth_scope: Optional[AuthScopeEnum] = Field(default=None, description="Determines the required authentication granularity. 'platform' uses shared platform credentials, 'mentor' requires mentor-level credentials, and 'user' requires each user to authenticate individually.  * `platform` - Platform * `mentor` - Mentor * `user` - User")
    oauth_service: Optional[StrictInt] = None
    oauth_service_data: OAuthService
    mcp_server_connections: StrictStr
    is_enabled: Optional[StrictBool] = Field(default=None, description="Whether the MCP server is enabled or not.")
    created_at: datetime
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["id", "platform", "mentor", "owner", "name", "description", "url", "image", "transport", "credentials", "extra_headers", "platform_key", "is_featured", "auth_type", "auth_scope", "oauth_service", "oauth_service_data", "mcp_server_connections", "is_enabled", "created_at", "updated_at"]

    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 MCPServer 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "platform",
            "platform_key",
            "oauth_service_data",
            "mcp_server_connections",
            "created_at",
            "updated_at",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of oauth_service_data
        if self.oauth_service_data:
            _dict['oauth_service_data'] = self.oauth_service_data.to_dict()
        # set to None if mentor (nullable) is None
        # and model_fields_set contains the field
        if self.mentor is None and "mentor" in self.model_fields_set:
            _dict['mentor'] = None

        # set to None if owner (nullable) is None
        # and model_fields_set contains the field
        if self.owner is None and "owner" in self.model_fields_set:
            _dict['owner'] = None

        # set to None if image (nullable) is None
        # and model_fields_set contains the field
        if self.image is None and "image" in self.model_fields_set:
            _dict['image'] = None

        # set to None if extra_headers (nullable) is None
        # and model_fields_set contains the field
        if self.extra_headers is None and "extra_headers" in self.model_fields_set:
            _dict['extra_headers'] = None

        # set to None if oauth_service (nullable) is None
        # and model_fields_set contains the field
        if self.oauth_service is None and "oauth_service" in self.model_fields_set:
            _dict['oauth_service'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "platform": obj.get("platform"),
            "mentor": obj.get("mentor"),
            "owner": obj.get("owner"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "url": obj.get("url"),
            "image": obj.get("image"),
            "transport": obj.get("transport"),
            "credentials": obj.get("credentials"),
            "extra_headers": obj.get("extra_headers"),
            "platform_key": obj.get("platform_key"),
            "is_featured": obj.get("is_featured"),
            "auth_type": obj.get("auth_type"),
            "auth_scope": obj.get("auth_scope"),
            "oauth_service": obj.get("oauth_service"),
            "oauth_service_data": OAuthService.from_dict(obj["oauth_service_data"]) if obj.get("oauth_service_data") is not None else None,
            "mcp_server_connections": obj.get("mcp_server_connections"),
            "is_enabled": obj.get("is_enabled"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


