# 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 .entity_id import EntityId
from .trade_traversal_entity import TradeTraversalEntity
from .trade_traversal_path_or_segment import TradeTraversalPathOrSegment


class UpstreamTradeTraversalResponse(pydantic_v1.BaseModel):
    """
    Examples
    --------
    from sayari import (
        TradeTraversalEntity,
        TradeTraversalPath,
        TradeTraversalPathSegment,
        TradeTraversalPathSegments,
        TradeTraversalProduct,
        UpstreamTradeTraversalResponse,
    )

    UpstreamTradeTraversalResponse(
        paths=[
            TradeTraversalPath(
                start="ESkH7J-UCRfY5t0_JXIH3w",
                end="A84F35yJ_3FT_hVzD9EzAw",
                paths=[
                    TradeTraversalPathSegments(
                        segments=[
                            TradeTraversalPathSegment(
                                src="A84F35yJ_3FT_hVzD9EzAw",
                                dst="ESkH7J-UCRfY5t0_JXIH3w",
                                products=[
                                    TradeTraversalProduct(
                                        hs_code="3206",
                                        min_date="2023-01-01",
                                        max_date="2023-11-25",
                                        arrival_countries=["VNM"],
                                        departure_countries=["IND"],
                                    ),
                                    TradeTraversalProduct(
                                        hs_code="3204",
                                        min_date="2023-03-01",
                                        max_date="2023-11-25",
                                        arrival_countries=["VNM"],
                                        departure_countries=["IND"],
                                    ),
                                ],
                            )
                        ],
                    )
                ],
            )
        ],
        entities={
            "ESkH7J-UCRfY5t0_JXIH3w": TradeTraversalEntity(
                type="company",
                label="ACUMEN HOUSEWARE INDUSTRY VIETNAM CO LTD",
                countries=["VNM"],
                risks=[],
            ),
            "A84F35yJ_3FT_hVzD9EzAw": TradeTraversalEntity(
                type="company",
                label="TOYO INK INDIA PRIVATE LIMITED",
                countries=["IND"],
                risks=[
                    "forced_labor_sheffield_hallam_university_reports_origin_subtier",
                    "forced_labor_uflpa_origin_subtier",
                    "forced_labor_xinjiang_origin_subtier",
                ],
            ),
        },
    )
    """

    status: typing.Optional[int] = None
    success: typing.Optional[bool] = None
    message: typing.Optional[str] = None
    entities: typing.Dict[EntityId, TradeTraversalEntity]
    paths: TradeTraversalPathOrSegment

    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}
