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

import datetime as dt
import typing

from ...base_types.types.paginated_response import PaginatedResponse
from ...core.datetime_utils import serialize_datetime
from ...core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1
from .project_entities_aggs import ProjectEntitiesAggs
from .project_entity import ProjectEntity


class GetProjectEntitiesResponse(PaginatedResponse):
    """
    Examples
    --------
    from sayari import (
        BucketAgg,
        CoreEntity,
        GetProjectEntitiesResponse,
        HsCodeAgg,
        HsCodeAggBucket,
        HsCodeAggTerms,
        IntKeyValue,
        ProjectEntitiesAggs,
        ProjectEntity,
        ProjectEntityUpstream,
        PsaSummary,
        QualifiedCount,
        RiskData,
        SourceCountInfo,
        TradeCount,
    )

    GetProjectEntitiesResponse(
        limit=10000,
        size=QualifiedCount(
            count=1,
            qualifier="eq",
        ),
        data=[
            ProjectEntity(
                type="entity",
                id="GOeOE8",
                project="gPq6EY",
                label="RAMESH FLOWERS PRIVATE LIMITED",
                created="2024-03-08 18:52:59.41176+00",
                updated="2024-03-08 18:52:59.41176+00",
                updated_by="auth0|5e45bd8caccd890e68147513",
                version=0,
                entity_id="FyI9lrlmA-7z_3enlTOhlw",
                tag_ids=[],
                case_status="not_assigned",
                received_hs_codes=["271290", "271220"],
                shipped_hs_codes=[],
                trade_count_incl_mg=TradeCount(
                    receiver_of=5,
                    shipper_of=0,
                ),
                match_strength={
                    "rules": {
                        "is_strong_v1": false,
                        "any_v1": "",
                        "is_any_v1": false,
                        "strong_v1": "",
                        "is_weak_v1": false,
                        "weak_v1": "",
                        "strength_v1": "none",
                    }
                },
                upstream=ProjectEntityUpstream(
                    risk=[],
                    countries=[],
                ),
                psa=PsaSummary(
                    risk=[
                        "eu_high_risk_third",
                        "basel_aml",
                        "cpi_score",
                        "owner_of_regulatory_action_entity",
                    ],
                    countries=["USA", "CAN", "MAR", "BEL", "GEO"],
                    count=2,
                ),
                summary=CoreEntity(
                    id="FyI9lrlmA-7z_3enlTOhlw",
                    type="company",
                    label="RAMESH FLOWERS PRIVATE LIMITED",
                    identifiers=[],
                    addresses=[
                        "A62(A) SIPCOT INDUSTRIAL COMPLEX THERKU VEERAPANDIAPURAM P.O. TUTICORIN628002 TAMIL NADU INDIA GSTIN 33AAACR9251P1ZY IEC 3595005775 PANNO AAACR92",
                        "A62(A) SIPCOT INDUSTRIAL COMPLEX TUTICORIN628002 TAMIL NADU INDIA GSTIN 33AAACR9251P1ZY IEC 3595005775 PH914612340505 TO 2340509",
                    ],
                    countries=["IND"],
                    names=["RAMESH FLOWERS PRIVATE LIMITED"],
                    related_entities_count=8,
                    user_related_entities_count=0,
                    relationship_counts={
                        "notify_party_of": 5,
                        "receives_from": 3,
                        "receiver_of": 5,
                    },
                    user_relationship_counts={},
                    attribute_counts={"name": 1, "country": 1, "address": 2},
                    trade_count={"sent": 0, "received": 5},
                    user_attribute_counts={},
                    record_count=5,
                    user_record_count=0,
                    source_counts={
                        "faa9caafcfabcee04ef2f0b21dd9197a": SourceCountInfo(
                            count=10,
                            label="South Korea Imports & Exports (2021 - Present)",
                        )
                    },
                    risk={
                        "forced_labor_xinjiang_origin_subtier": RiskData(
                            value=3.0,
                            metadata={},
                            level="high",
                        ),
                        "basel_aml": RiskData(
                            value=4.95,
                            metadata={"country": ["IND"]},
                            level="relevant",
                        ),
                        "forced_labor_sheffield_hallam_university_reports_origin_subtier": RiskData(
                            value=3.0,
                            metadata={},
                            level="high",
                        ),
                        "cpi_score": RiskData(
                            value=40.0,
                            metadata={"country": ["IND"]},
                            level="relevant",
                        ),
                        "forced_labor_uflpa_origin_subtier": RiskData(
                            value=3.0,
                            metadata={},
                            level="high",
                        ),
                    },
                    attributes={
                        "address": [
                            {
                                "value": {
                                    "value": "A62(A) SIPCOT INDUSTRIAL COMPLEX THERKU VEERAPANDIAPURAM P.O. TUTICORIN628002 TAMIL NADU INDIA GSTIN 33AAACR9251P1ZY IEC 3595005775 PANNO AAACR92",
                                    "house": "Gstin 33aaacr9251p1zy",
                                    "house_number": "3595005775",
                                    "road": "Panno",
                                    "city": "NADU",
                                    "state": "Tamil Nadu",
                                    "postcode": "Aaacr92",
                                    "country": "India",
                                    "x": 74.99698,
                                    "y": 12.85316,
                                    "precision_code": "G3",
                                    "normalized": "33AAACR9251P1ZY 3595005775 A62A AAACR92 COMPLEX GSTIN IEC INDIA INDUSTRIAL NADU O P PANNO SIPCOT TAMIL THERKU TUTICORIN628002 VEERAPANDIAPURAM",
                                },
                                "properties": [
                                    {
                                        "record": "faa9caafcfabcee04ef2f0b21dd9197a/MAEU226738031/1693109172077",
                                        "record_count": 4,
                                        "editable": false,
                                    }
                                ],
                            },
                            {
                                "value": {
                                    "value": "A62(A) SIPCOT INDUSTRIAL COMPLEX TUTICORIN628002 TAMIL NADU INDIA GSTIN 33AAACR9251P1ZY IEC 3595005775 PH914612340505 TO 2340509",
                                    "house": "Gstin 33aaacr9251p1zy",
                                    "house_number": "3595005775",
                                    "road": "Ph914612340505 To 2340509",
                                    "city": "TO",
                                    "state": "Tamil Nadu",
                                    "postcode": "Tuticorin628002",
                                    "country": "India",
                                    "x": 77.06,
                                    "y": 20.00896,
                                    "precision_code": "G3",
                                    "normalized": "2340509 33AAACR9251P1ZY 3595005775 A62A COMPLEX GSTIN IEC INDIA INDUSTRIAL NADU PH914612340505 SIPCOT TAMIL TO TUTICORIN628002",
                                },
                                "properties": [
                                    {
                                        "record": "faa9caafcfabcee04ef2f0b21dd9197a/MAEU1KT860018/1693109343516",
                                        "record_count": 2,
                                        "editable": false,
                                    }
                                ],
                            },
                        ],
                        "country": [
                            {
                                "value": {
                                    "value": "IND",
                                    "context": "address",
                                    "Original Text": "India",
                                },
                                "properties": [
                                    {
                                        "record": "faa9caafcfabcee04ef2f0b21dd9197a/MAEU226738031/1693109172077",
                                        "record_count": 6,
                                        "editable": false,
                                    }
                                ],
                            }
                        ],
                        "name": [
                            {
                                "value": {
                                    "value": "RAMESH FLOWERS PRIVATE LIMITED",
                                    "context": "primary",
                                },
                                "properties": [
                                    {
                                        "record": "faa9caafcfabcee04ef2f0b21dd9197a/MAEU226738031/1693109172077",
                                        "record_count": 10,
                                        "editable": false,
                                    }
                                ],
                            }
                        ],
                    },
                ),
            )
        ],
        aggregations=ProjectEntitiesAggs(
            risk=[
                BucketAgg(
                    key="basel_aml",
                    doc_count=1,
                ),
                BucketAgg(
                    key="cpi_score",
                    doc_count=1,
                ),
                BucketAgg(
                    key="forced_labor_xinjiang_origin_subtier",
                    doc_count=1,
                ),
                BucketAgg(
                    key="forced_labor_uflpa_origin_subtier",
                    doc_count=1,
                ),
                BucketAgg(
                    key="forced_labor_sheffield_hallam_university_reports_origin_subtier",
                    doc_count=1,
                ),
            ],
            tag_ids=[],
            upstream_risk=[],
            hit_count=[
                BucketAgg(
                    key="hit_count",
                    doc_count=1,
                )
            ],
            country=[
                BucketAgg(
                    key="IND",
                    doc_count=1,
                    label="India",
                )
            ],
            shipment_counts=[
                BucketAgg(
                    key="receiver_of",
                    doc_count=5,
                    comment="Sum of all shipments of this type across matching documents",
                ),
                BucketAgg(
                    key="shipper_of",
                    doc_count=0,
                    comment="Sum of all shipments of this type across matching documents",
                ),
            ],
            source=[
                BucketAgg(
                    key="faa9caafcfabcee04ef2f0b21dd9197a",
                    label="South Korea Imports & Exports (2021 - Present)",
                    doc_count=1,
                )
            ],
            source_type=[
                BucketAgg(
                    key="trade_data",
                    doc_count=1,
                )
            ],
            region=[
                BucketAgg(
                    key="asia_pacific",
                    doc_count=1,
                )
            ],
            match_results=[
                BucketAgg(
                    key="sayari",
                    doc_count=1,
                )
            ],
            business_purpose=[],
            upstream_country=[],
            received_hs_codes=HsCodeAgg(
                doc_count=2,
                hs_code_terms=HsCodeAggTerms(
                    doc_count_error_upper_bound=0,
                    sum_other_doc_count=0,
                    buckets=[
                        HsCodeAggBucket(
                            key="271290",
                            doc_count=1,
                            hs_code_sums=IntKeyValue(
                                value=4,
                            ),
                        ),
                        HsCodeAggBucket(
                            key="271220",
                            doc_count=1,
                            hs_code_sums=IntKeyValue(
                                value=1,
                            ),
                        ),
                    ],
                ),
            ),
            case_statuses=[
                BucketAgg(
                    key="not_assigned",
                    doc_count=1,
                )
            ],
            shipped_hs_codes=HsCodeAgg(
                doc_count=0,
                hs_code_terms=HsCodeAggTerms(
                    doc_count_error_upper_bound=0,
                    sum_other_doc_count=0,
                    buckets=[],
                ),
            ),
        ),
    )
    """

    next: typing.Optional[str] = None
    prev: typing.Optional[str] = None
    data: typing.List[ProjectEntity]
    aggregations: ProjectEntitiesAggs

    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
        allow_population_by_field_name = True
        populate_by_name = True
        extra = pydantic_v1.Extra.allow
        json_encoders = {dt.datetime: serialize_datetime}
