# coding: utf-8

"""
    Arthur Scope

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

    The version of the OpenAPI document: 0.1.0
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List
from arthur_client.api_bindings.models.custom_aggregation_spec_schema_aggregate_args_inner import CustomAggregationSpecSchemaAggregateArgsInner
from arthur_client.api_bindings.models.reported_custom_aggregation import ReportedCustomAggregation
from arthur_client.api_bindings.models.user import User
from typing import Optional, Set
from typing_extensions import Self

class CustomAggregationSpecSchema(BaseModel):
    """
    CustomAggregationSpecSchema
    """ # noqa: E501
    name: StrictStr = Field(description="Name of the custom aggregation function.")
    description: StrictStr = Field(description="Description of the custom aggregation function and what it aggregates.")
    reported_aggregations: List[ReportedCustomAggregation] = Field(description="Metadata for every aggregation the custom aggregation reports.")
    aggregate_args: List[CustomAggregationSpecSchemaAggregateArgsInner] = Field(description="List of parameters to the custom aggregation's query function.")
    sql: StrictStr = Field(description="DuckDBSQL query for the custom aggregation.")
    id: StrictStr = Field(description="Unique identifier of the custom aggregation function.")
    workspace_id: StrictStr = Field(description="Unique identifier of the custom aggregation's parent workspace.")
    version: StrictInt = Field(description="Version number of the custom aggregation function.")
    authored_by: User = Field(description="User who authored this custom aggregation.")
    created_at: datetime = Field(description="Time of aggregation creation.")
    __properties: ClassVar[List[str]] = ["name", "description", "reported_aggregations", "aggregate_args", "sql", "id", "workspace_id", "version", "authored_by", "created_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 CustomAggregationSpecSchema 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 reported_aggregations (list)
        _items = []
        if self.reported_aggregations:
            for _item_reported_aggregations in self.reported_aggregations:
                if _item_reported_aggregations:
                    _items.append(_item_reported_aggregations.to_dict())
            _dict['reported_aggregations'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in aggregate_args (list)
        _items = []
        if self.aggregate_args:
            for _item_aggregate_args in self.aggregate_args:
                if _item_aggregate_args:
                    _items.append(_item_aggregate_args.to_dict())
            _dict['aggregate_args'] = _items
        # override the default output from pydantic by calling `to_dict()` of authored_by
        if self.authored_by:
            _dict['authored_by'] = self.authored_by.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "description": obj.get("description"),
            "reported_aggregations": [ReportedCustomAggregation.from_dict(_item) for _item in obj["reported_aggregations"]] if obj.get("reported_aggregations") is not None else None,
            "aggregate_args": [CustomAggregationSpecSchemaAggregateArgsInner.from_dict(_item) for _item in obj["aggregate_args"]] if obj.get("aggregate_args") is not None else None,
            "sql": obj.get("sql"),
            "id": obj.get("id"),
            "workspace_id": obj.get("workspace_id"),
            "version": obj.get("version"),
            "authored_by": User.from_dict(obj["authored_by"]) if obj.get("authored_by") is not None else None,
            "created_at": obj.get("created_at")
        })
        return _obj


