# coding: utf-8

"""
    CATAPA API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0.0
    Contact: support@catapa.com
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from openapi_client.models.analytics_chart_data_series_response import AnalyticsChartDataSeriesResponse
from openapi_client.models.analytics_color_scheme_response import AnalyticsColorSchemeResponse
from openapi_client.models.chart_filter_response import ChartFilterResponse
from typing import Optional, Set
from typing_extensions import Self

class AnalyticsChartDataResponse(BaseModel):
    """
    AnalyticsChartDataResponse
    """ # noqa: E501
    title: Optional[StrictStr] = Field(default=None, description="Title of the analytics chart")
    size: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Size of the chart")
    options: Optional[StrictStr] = Field(default=None, description="Additional chart options")
    chart_type: Optional[StrictStr] = Field(default=None, description="Type of the chart (e.g., BAR_VERTICAL_GROUPED_CHART)", alias="chartType")
    yaxis_title: Optional[StrictStr] = Field(default=None, description="Title for Y-axis", alias="yaxisTitle")
    ycolumn_type: Optional[StrictStr] = Field(default=None, description="Data type of Y-axis column", alias="ycolumnType")
    xaxis_title: Optional[StrictStr] = Field(default=None, description="Title for X-axis", alias="xaxisTitle")
    xcolumn_type: Optional[StrictStr] = Field(default=None, description="Data type of X-axis column", alias="xcolumnType")
    series_axis_title: Optional[StrictStr] = Field(default=None, description="Title for series axis", alias="seriesAxisTitle")
    series_column_type: Optional[StrictStr] = Field(default=None, description="Data type of series column", alias="seriesColumnType")
    categories: Optional[List[StrictStr]] = Field(default=None, description="Chart categories")
    series: Optional[List[AnalyticsChartDataSeriesResponse]] = Field(default=None, description="Chart series data")
    color_scheme: Optional[AnalyticsColorSchemeResponse] = Field(default=None, alias="colorScheme")
    chart_filters: Optional[List[ChartFilterResponse]] = Field(default=None, description="Chart filter configurations", alias="chartFilters")
    __properties: ClassVar[List[str]] = ["title", "size", "options", "chartType", "yaxisTitle", "ycolumnType", "xaxisTitle", "xcolumnType", "seriesAxisTitle", "seriesColumnType", "categories", "series", "colorScheme", "chartFilters"]

    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 AnalyticsChartDataResponse 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 series (list)
        _items = []
        if self.series:
            for _item_series in self.series:
                if _item_series:
                    _items.append(_item_series.to_dict())
            _dict['series'] = _items
        # override the default output from pydantic by calling `to_dict()` of color_scheme
        if self.color_scheme:
            _dict['colorScheme'] = self.color_scheme.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in chart_filters (list)
        _items = []
        if self.chart_filters:
            for _item_chart_filters in self.chart_filters:
                if _item_chart_filters:
                    _items.append(_item_chart_filters.to_dict())
            _dict['chartFilters'] = _items
        # set to None if options (nullable) is None
        # and model_fields_set contains the field
        if self.options is None and "options" in self.model_fields_set:
            _dict['options'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "title": obj.get("title"),
            "size": obj.get("size"),
            "options": obj.get("options"),
            "chartType": obj.get("chartType"),
            "yaxisTitle": obj.get("yaxisTitle"),
            "ycolumnType": obj.get("ycolumnType"),
            "xaxisTitle": obj.get("xaxisTitle"),
            "xcolumnType": obj.get("xcolumnType"),
            "seriesAxisTitle": obj.get("seriesAxisTitle"),
            "seriesColumnType": obj.get("seriesColumnType"),
            "categories": obj.get("categories"),
            "series": [AnalyticsChartDataSeriesResponse.from_dict(_item) for _item in obj["series"]] if obj.get("series") is not None else None,
            "colorScheme": AnalyticsColorSchemeResponse.from_dict(obj["colorScheme"]) if obj.get("colorScheme") is not None else None,
            "chartFilters": [ChartFilterResponse.from_dict(_item) for _item in obj["chartFilters"]] if obj.get("chartFilters") is not None else None
        })
        return _obj


