# coding: utf-8

"""
    Moodle Webservice API

    Auto-generated OpenAPI spec for Moodle's Webservice API.

    The version of the OpenAPI document: 5.0.3 (Build: 20251006)
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.mod_lti_create_tool_type_response_state import ModLtiCreateToolTypeResponseState
from poodle_async_full.models.mod_lti_create_tool_type_response_urls import ModLtiCreateToolTypeResponseUrls
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModLtiUpdateToolTypeResponse(BaseModel):
    """
    Tool
    """ # noqa: E501
    capabilitygroups: Optional[List[Optional[StrictStr]]] = Field(default=None, description="Array of capability groups")
    clientid: Optional[StrictStr] = Field(description="Client ID")
    courseid: Optional[StrictInt] = Field(default=0, description="Tool type course")
    deploymentid: Optional[StrictInt] = Field(description="Deployment ID")
    description: Optional[StrictStr] = Field(description="Tool type description")
    hascapabilitygroups: Optional[StrictBool] = Field(description="Indicate if capabilitygroups is populated")
    id: Optional[StrictInt] = Field(description="Tool type id")
    instancecount: Optional[StrictInt] = Field(description="The number of times this tool is being used")
    instanceids: Optional[List[Optional[StrictInt]]] = Field(default=None, description="IDs for the LTI instances using this type")
    name: Optional[StrictStr] = Field(description="Tool type name")
    platformid: Optional[StrictStr] = Field(description="Platform ID")
    state: ModLtiCreateToolTypeResponseState
    urls: ModLtiCreateToolTypeResponseUrls
    __properties: ClassVar[List[str]] = ["capabilitygroups", "clientid", "courseid", "deploymentid", "description", "hascapabilitygroups", "id", "instancecount", "instanceids", "name", "platformid", "state", "urls"]

    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 ModLtiUpdateToolTypeResponse 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 state
        if self.state:
            _dict['state'] = self.state.to_dict()
        # override the default output from pydantic by calling `to_dict()` of urls
        if self.urls:
            _dict['urls'] = self.urls.to_dict()
        # set to None if clientid (nullable) is None
        # and model_fields_set contains the field
        if self.clientid is None and "clientid" in self.model_fields_set:
            _dict['clientid'] = None

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

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

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

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

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

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

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

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

        return _dict

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

        relaxed = settings.relaxe_all_models or "ModLtiUpdateToolTypeResponse" in settings.relaxed_models

        if not isinstance(obj, dict):
            return cls.model_construct(**obj) if relaxed else cls.model_validate(obj)

        data = {
            "capabilitygroups": obj.get("capabilitygroups"),
            "clientid": obj.get("clientid"),
            "courseid": obj.get("courseid") if obj.get("courseid") is not None else 0,
            "deploymentid": obj.get("deploymentid"),
            "description": obj.get("description"),
            "hascapabilitygroups": obj.get("hascapabilitygroups"),
            "id": obj.get("id"),
            "instancecount": obj.get("instancecount"),
            "instanceids": obj.get("instanceids"),
            "name": obj.get("name"),
            "platformid": obj.get("platformid"),
            "state": ModLtiCreateToolTypeResponseState.from_dict(obj["state"]) if obj.get("state") is not None else None,
            "urls": ModLtiCreateToolTypeResponseUrls.from_dict(obj["urls"]) if obj.get("urls") is not None else None
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


