# 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
from typing import Any, ClassVar, Dict, List, Optional
from iblai.models.learner_analytics_result import LearnerAnalyticsResult
from iblai.models.learner_summary import LearnerSummary
from iblai.models.overtime_data_point import OvertimeDataPoint
from iblai.models.pagination import Pagination
from iblai.models.user_info import UserInfo
from typing import Optional, Set
from typing_extensions import Self

class LearnerAnalyticsResponse(BaseModel):
    """
    Unified response serializer for learner analytics endpoint.
    """ # noqa: E501
    user: UserInfo
    summary: LearnerSummary
    results: List[LearnerAnalyticsResult]
    pagination: Pagination
    overtime: Optional[List[OvertimeDataPoint]] = Field(default=None, description="Time spent over time data (when overtime=true)")
    generated_at: datetime
    __properties: ClassVar[List[str]] = ["user", "summary", "results", "pagination", "overtime", "generated_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 LearnerAnalyticsResponse 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 user
        if self.user:
            _dict['user'] = self.user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of summary
        if self.summary:
            _dict['summary'] = self.summary.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in results (list)
        _items = []
        if self.results:
            for _item_results in self.results:
                if _item_results:
                    _items.append(_item_results.to_dict())
            _dict['results'] = _items
        # override the default output from pydantic by calling `to_dict()` of pagination
        if self.pagination:
            _dict['pagination'] = self.pagination.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in overtime (list)
        _items = []
        if self.overtime:
            for _item_overtime in self.overtime:
                if _item_overtime:
                    _items.append(_item_overtime.to_dict())
            _dict['overtime'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "user": UserInfo.from_dict(obj["user"]) if obj.get("user") is not None else None,
            "summary": LearnerSummary.from_dict(obj["summary"]) if obj.get("summary") is not None else None,
            "results": [LearnerAnalyticsResult.from_dict(_item) for _item in obj["results"]] if obj.get("results") is not None else None,
            "pagination": Pagination.from_dict(obj["pagination"]) if obj.get("pagination") is not None else None,
            "overtime": [OvertimeDataPoint.from_dict(_item) for _item in obj["overtime"]] if obj.get("overtime") is not None else None,
            "generated_at": obj.get("generated_at")
        })
        return _obj


