# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ..core.datetime_utils import serialize_datetime
from ..core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1
from .create_or_update_condition_request_body_condition_type import CreateOrUpdateConditionRequestBodyConditionType
from .create_or_update_condition_request_body_metric_period import CreateOrUpdateConditionRequestBodyMetricPeriod
from .create_or_update_condition_request_body_operator import CreateOrUpdateConditionRequestBodyOperator


class CreateOrUpdateConditionRequestBody(pydantic_v1.BaseModel):
    comparison_trait_id: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    Optionally provide a trait ID to compare a metric or trait value against instead of a value
    """

    condition_type: CreateOrUpdateConditionRequestBodyConditionType
    event_subtype: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    Name of track event type used to measure this condition
    """

    id: typing.Optional[str] = None
    metric_period: typing.Optional[CreateOrUpdateConditionRequestBodyMetricPeriod] = pydantic_v1.Field(default=None)
    """
    Period of time over which to measure the track event metric
    """

    metric_value: int = pydantic_v1.Field()
    """
    Value to compare the track event metric against
    """

    operator: CreateOrUpdateConditionRequestBodyOperator
    resource_ids: typing.List[str] = pydantic_v1.Field()
    """
    List of resource IDs (companies, users, or plans) targeted by this condition
    """

    trait_id: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    ID of trait to use to measure this condition
    """

    trait_value: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    Value to compare the trait value against
    """

    def json(self, **kwargs: typing.Any) -> str:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().json(**kwargs_with_defaults)

    def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
        kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs}

        return deep_union_pydantic_dicts(
            super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none)
        )

    class Config:
        frozen = True
        smart_union = True
        extra = pydantic_v1.Extra.allow
        json_encoders = {dt.datetime: serialize_datetime}
