# 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, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from openapi_client.models.chart_filter_request import ChartFilterRequest
from openapi_client.models.chart_table_relation_request import ChartTableRelationRequest
from openapi_client.models.id_request import IdRequest
from typing import Optional, Set
from typing_extensions import Self

class AnalyticsChartRequest(BaseModel):
    """
    AnalyticsChartRequest
    """ # noqa: E501
    title: StrictStr
    size: Union[StrictFloat, StrictInt]
    options: Optional[StrictStr] = None
    chart_type: StrictStr = Field(alias="chartType")
    aggregation_type: StrictStr = Field(alias="aggregationType")
    table_id: StrictStr = Field(alias="tableId")
    yaxis_title: StrictStr = Field(alias="yaxisTitle")
    ycolumn_id: StrictStr = Field(alias="ycolumnId")
    ychart_table_relations: List[ChartTableRelationRequest] = Field(alias="ychartTableRelations")
    xaxis_title: StrictStr = Field(alias="xaxisTitle")
    xcolumn_id: StrictStr = Field(alias="xcolumnId")
    xchart_table_relations: List[ChartTableRelationRequest] = Field(alias="xchartTableRelations")
    series_axis_title: Optional[StrictStr] = Field(default=None, alias="seriesAxisTitle")
    series_column_id: Optional[StrictStr] = Field(default=None, alias="seriesColumnId")
    series_chart_table_relations: Optional[List[ChartTableRelationRequest]] = Field(default=None, alias="seriesChartTableRelations")
    color_scheme: IdRequest = Field(alias="colorScheme")
    data_trustee_enabled: Optional[StrictBool] = Field(default=None, alias="dataTrusteeEnabled")
    chart_filters: Optional[List[ChartFilterRequest]] = Field(default=None, alias="chartFilters")
    max_items: Union[StrictFloat, StrictInt] = Field(alias="maxItems")
    sort_type: StrictStr = Field(alias="sortType")
    __properties: ClassVar[List[str]] = ["title", "size", "options", "chartType", "aggregationType", "tableId", "yaxisTitle", "ycolumnId", "ychartTableRelations", "xaxisTitle", "xcolumnId", "xchartTableRelations", "seriesAxisTitle", "seriesColumnId", "seriesChartTableRelations", "colorScheme", "dataTrusteeEnabled", "chartFilters", "maxItems", "sortType"]

    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 AnalyticsChartRequest 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 ychart_table_relations (list)
        _items = []
        if self.ychart_table_relations:
            for _item_ychart_table_relations in self.ychart_table_relations:
                if _item_ychart_table_relations:
                    _items.append(_item_ychart_table_relations.to_dict())
            _dict['ychartTableRelations'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in xchart_table_relations (list)
        _items = []
        if self.xchart_table_relations:
            for _item_xchart_table_relations in self.xchart_table_relations:
                if _item_xchart_table_relations:
                    _items.append(_item_xchart_table_relations.to_dict())
            _dict['xchartTableRelations'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in series_chart_table_relations (list)
        _items = []
        if self.series_chart_table_relations:
            for _item_series_chart_table_relations in self.series_chart_table_relations:
                if _item_series_chart_table_relations:
                    _items.append(_item_series_chart_table_relations.to_dict())
            _dict['seriesChartTableRelations'] = _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_id (nullable) is None
        # and model_fields_set contains the field
        if self.series_column_id is None and "series_column_id" in self.model_fields_set:
            _dict['seriesColumnId'] = None

        # set to None if series_chart_table_relations (nullable) is None
        # and model_fields_set contains the field
        if self.series_chart_table_relations is None and "series_chart_table_relations" in self.model_fields_set:
            _dict['seriesChartTableRelations'] = 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 AnalyticsChartRequest 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"),
            "aggregationType": obj.get("aggregationType"),
            "tableId": obj.get("tableId"),
            "yaxisTitle": obj.get("yaxisTitle"),
            "ycolumnId": obj.get("ycolumnId"),
            "ychartTableRelations": [ChartTableRelationRequest.from_dict(_item) for _item in obj["ychartTableRelations"]] if obj.get("ychartTableRelations") is not None else None,
            "xaxisTitle": obj.get("xaxisTitle"),
            "xcolumnId": obj.get("xcolumnId"),
            "xchartTableRelations": [ChartTableRelationRequest.from_dict(_item) for _item in obj["xchartTableRelations"]] if obj.get("xchartTableRelations") is not None else None,
            "seriesAxisTitle": obj.get("seriesAxisTitle"),
            "seriesColumnId": obj.get("seriesColumnId"),
            "seriesChartTableRelations": [ChartTableRelationRequest.from_dict(_item) for _item in obj["seriesChartTableRelations"]] if obj.get("seriesChartTableRelations") is not None else None,
            "colorScheme": IdRequest.from_dict(obj["colorScheme"]) if obj.get("colorScheme") is not None else None,
            "dataTrusteeEnabled": obj.get("dataTrusteeEnabled"),
            "chartFilters": [ChartFilterRequest.from_dict(_item) for _item in obj["chartFilters"]] if obj.get("chartFilters") is not None else None,
            "maxItems": obj.get("maxItems"),
            "sortType": obj.get("sortType")
        })
        return _obj


