"""Auto-generated by delta-registry-website/lib/schema-generator — do not hand-edit.
Source: Apify actor 'actor-19-maritime-sanctions-monitor' (local .actor/input_schema.json), generated 2026-09-18.
Regenerate with: node generate-all.js
"""
import os
from typing import Optional

import requests
from pydantic import BaseModel, Field
from langchain_core.tools import StructuredTool

APIFY_ACTOR_ID = 'dR68wHyuOLS2WEhmo'  # stefano_seggio/actor-19-maritime-sanctions-monitor
APIFY_RUN_SYNC_URL = f"https://api.apify.com/v2/acts/{APIFY_ACTOR_ID}/run-sync-get-dataset-items"


class Actor19MaritimeSanctionsMonitorInput(BaseModel):
    """Mirrors actor-19-maritime-sanctions-monitor's real .actor/input_schema.json field-for-field."""

    maxItems: Optional[int] = Field(default=250, ge=1, description='Hard cap on how many vessel-type SDN records to return this run, taken in the order OFAC lists them in the source feed.')
    onlyNew: Optional[bool] = Field(default=False, description='When enabled, persists a content fingerprint per vessel (uid) between runs in this actor\'s own key-value store and returns only records that are new since the last run OR whose sanctions program(s) or other tracked fields changed since they were last seen - records identical to last time are skipped. Vessels no longer present in the current OFAC feed are always reported as DELISTED regardless of this setting (when the run was not itself truncated by maxItems - see the DELISTED section of README.md). Recommended for recurring monitoring; leave off for a full extraction of the current vessel-type SDN list.')
    enrichWithUnConsolidatedList: Optional[bool] = Field(default=True, description='When enabled (default), additionally fetches the UN Security Council Consolidated Sanctions List and flags OFAC vessel records whose IMO number is also mentioned in a UN entity\'s designation text. Adds one extra live fetch and a linear scan of the UN list per run; disable for a faster OFAC-only run.')
    programFilter: Optional[list[str]] = Field(default=None, description='Optional: only return vessels whose Program list contains at least one of these OFAC program codes (case-insensitive substring match, e.g. "IRAN", "DPRK2", "RUSSIA-EO14024"). Leave empty to return vessels from all programs.')
    vesselNameContains: Optional[str] = Field(default=None, description='Optional case-insensitive substring filter on the vessel\'s listed name, applied before maxItems. Useful for a narrow monitoring run against one vessel of interest.')


def _run_actor_19_maritime_sanctions_monitor(maxItems: Optional[int] = None, onlyNew: Optional[bool] = None, enrichWithUnConsolidatedList: Optional[bool] = None, programFilter: Optional[list[str]] = None, vesselNameContains: Optional[str] = None) -> list[dict]:
    token = os.environ["APIFY_TOKEN"]  # never hardcode the token
    payload = {
        **({"maxItems": maxItems} if maxItems is not None else {}),
        **({"onlyNew": onlyNew} if onlyNew is not None else {}),
        **({"enrichWithUnConsolidatedList": enrichWithUnConsolidatedList} if enrichWithUnConsolidatedList is not None else {}),
        **({"programFilter": programFilter} if programFilter is not None else {}),
        **({"vesselNameContains": vesselNameContains} if vesselNameContains is not None else {}),
    }
    resp = requests.post(
        APIFY_RUN_SYNC_URL,
        params={"token": token},
        json=payload,
        timeout=320,  # Apify's real run-sync-get-dataset-items cap is 300s
    )
    resp.raise_for_status()
    return resp.json()  # dataset items array, returned directly


run_actor_19_maritime_sanctions_monitor_tool = StructuredTool.from_function(
    func=_run_actor_19_maritime_sanctions_monitor,
    name='actor-19-maritime-sanctions-monitor',
    description='Screens the US Treasury OFAC Specially Designated Nationals vessel list against the UN Security Council Consolidated List by IMO number, delivering normalized ship-sanctions records with cross-run change detection: new designations, program changes, and vessel delistings.',
    args_schema=Actor19MaritimeSanctionsMonitorInput,
)
