# coding: utf-8

"""
    Graphiant APIs

    Graphiant API documentation.

    The version of the OpenAPI document: 1.0.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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from graphiant_sdk.models.v1_alarm_history_get200_response_history_inner_time import V1AlarmHistoryGet200ResponseHistoryInnerTime
from graphiant_sdk.models.v1_logs_post_request_selectors_inner import V1LogsPostRequestSelectorsInner
from typing import Optional, Set
from typing_extensions import Self

class V1LogsPostRequest(BaseModel):
    """
    V1LogsPostRequest
    """ # noqa: E501
    cursor_ref: Optional[StrictStr] = Field(default=None, alias="cursorRef")
    customer_view: Optional[StrictBool] = Field(default=None, alias="customerView")
    device_ids: Optional[List[Annotated[int, Field(strict=True, ge=0)]]] = Field(default=None, alias="deviceIds")
    histogram_bucket_size_sec: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, alias="histogramBucketSizeSec")
    num_logs: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, alias="numLogs")
    old_ts: Optional[V1AlarmHistoryGet200ResponseHistoryInnerTime] = Field(default=None, alias="oldTs")
    recent_ts: Optional[V1AlarmHistoryGet200ResponseHistoryInnerTime] = Field(default=None, alias="recentTs")
    selectors: Optional[List[V1LogsPostRequestSelectorsInner]] = None
    __properties: ClassVar[List[str]] = ["cursorRef", "customerView", "deviceIds", "histogramBucketSizeSec", "numLogs", "oldTs", "recentTs", "selectors"]

    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 V1LogsPostRequest 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 old_ts
        if self.old_ts:
            _dict['oldTs'] = self.old_ts.to_dict()
        # override the default output from pydantic by calling `to_dict()` of recent_ts
        if self.recent_ts:
            _dict['recentTs'] = self.recent_ts.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in selectors (list)
        _items = []
        if self.selectors:
            for _item_selectors in self.selectors:
                if _item_selectors:
                    _items.append(_item_selectors.to_dict())
            _dict['selectors'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "cursorRef": obj.get("cursorRef"),
            "customerView": obj.get("customerView"),
            "deviceIds": obj.get("deviceIds"),
            "histogramBucketSizeSec": obj.get("histogramBucketSizeSec"),
            "numLogs": obj.get("numLogs"),
            "oldTs": V1AlarmHistoryGet200ResponseHistoryInnerTime.from_dict(obj["oldTs"]) if obj.get("oldTs") is not None else None,
            "recentTs": V1AlarmHistoryGet200ResponseHistoryInnerTime.from_dict(obj["recentTs"]) if obj.get("recentTs") is not None else None,
            "selectors": [V1LogsPostRequestSelectorsInner.from_dict(_item) for _item in obj["selectors"]] if obj.get("selectors") is not None else None
        })
        return _obj


