# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from poodle_async_full.models.mod_scorm_get_scorm_scoes_response_scoes_inner_extradata_inner import ModScormGetScormScoesResponseScoesInnerExtradataInner
from typing import Optional, Set
from typing_extensions import Self

from poodle_async_full.configuration import settings

class ModScormGetScormScoesResponseScoesInner(BaseModel):
    """
    SCORM SCO data
    """ # noqa: E501
    extradata: Optional[List[ModScormGetScormScoesResponseScoesInnerExtradataInner]] = Field(default=None, description="Additional SCO data")
    id: Optional[StrictInt] = Field(description="sco id")
    identifier: Optional[StrictStr] = Field(description="identifier")
    launch: Optional[StrictStr] = Field(description="launch file")
    manifest: Optional[StrictStr] = Field(description="manifest id")
    organization: Optional[StrictStr] = Field(description="organization id")
    parent: Optional[StrictStr] = Field(description="parent")
    scorm: Optional[StrictInt] = Field(description="scorm id")
    scormtype: Optional[StrictStr] = Field(description="scorm type (asset, sco)")
    sortorder: Optional[StrictInt] = Field(description="sort order")
    title: Optional[StrictStr] = Field(description="sco title")
    __properties: ClassVar[List[str]] = ["extradata", "id", "identifier", "launch", "manifest", "organization", "parent", "scorm", "scormtype", "sortorder", "title"]

    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 ModScormGetScormScoesResponseScoesInner 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 extradata (list)
        _items = []
        if self.extradata:
            for _item_extradata in self.extradata:
                if _item_extradata:
                    _items.append(_item_extradata.to_dict())
            _dict['extradata'] = _items
        # 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 identifier (nullable) is None
        # and model_fields_set contains the field
        if self.identifier is None and "identifier" in self.model_fields_set:
            _dict['identifier'] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

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

        data = {
            "extradata": [ModScormGetScormScoesResponseScoesInnerExtradataInner.from_dict(_item) for _item in obj["extradata"]] if obj.get("extradata") is not None else None,
            "id": obj.get("id"),
            "identifier": obj.get("identifier"),
            "launch": obj.get("launch"),
            "manifest": obj.get("manifest"),
            "organization": obj.get("organization"),
            "parent": obj.get("parent"),
            "scorm": obj.get("scorm"),
            "scormtype": obj.get("scormtype"),
            "sortorder": obj.get("sortorder"),
            "title": obj.get("title")
        }
        _obj = cls.model_construct(**data) if relaxed else cls.model_validate(data)
        return _obj


