# coding: utf-8

"""
    FlowHunt

    FlowHunt API

    The version of the OpenAPI document: 2.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 flowhunt.models.tracking_event_create_request import TrackingEventCreateRequest
from typing import Optional, Set
from typing_extensions import Self

class TrackingEventCreateRequests(BaseModel):
    """
    TrackingEventCreateRequests
    """ # noqa: E501
    events: List[TrackingEventCreateRequest] = Field(description="The list of events to be created")
    unique_id: Optional[StrictStr] = None
    fp: Optional[StrictStr] = None
    session_id: Optional[StrictStr] = None
    with_address: Optional[StrictBool] = None
    ga: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["events", "unique_id", "fp", "session_id", "with_address", "ga"]

    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 TrackingEventCreateRequests 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 events (list)
        _items = []
        if self.events:
            for _item_events in self.events:
                if _item_events:
                    _items.append(_item_events.to_dict())
            _dict['events'] = _items
        # set to None if unique_id (nullable) is None
        # and model_fields_set contains the field
        if self.unique_id is None and "unique_id" in self.model_fields_set:
            _dict['unique_id'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "events": [TrackingEventCreateRequest.from_dict(_item) for _item in obj["events"]] if obj.get("events") is not None else None,
            "unique_id": obj.get("unique_id"),
            "fp": obj.get("fp"),
            "session_id": obj.get("session_id"),
            "with_address": obj.get("with_address"),
            "ga": obj.get("ga")
        })
        return _obj


