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

import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.unchecked_base_model import UncheckedBaseModel
from .credential_mapping import CredentialMapping
from .guided_step import GuidedStep
from .healed_step import HealedStep
from .source_sync_guided_crawl_settings_input_mode import SourceSyncGuidedCrawlSettingsInputMode


class SourceSyncGuidedCrawlSettingsInput(UncheckedBaseModel):
    """
    Settings for guided crawl source archetype.

    Simplified credential handling:
    - requires_login: checkbox to enable login fields
    - username: plain text username/email
    - password_secret_name: dropdown of secrets from vault
    """

    source_archetype_id: typing.Literal["com.scoutos.guided_crawl"] = "com.scoutos.guided_crawl"
    instructions: str = pydantic.Field()
    """
    Natural language instructions for the crawler (e.g., 'Login to portal, navigate to Documents, download all PDFs')
    """

    start_url: str = pydantic.Field()
    """
    URL to begin the guided crawl from
    """

    requires_login: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Enable if the site requires authentication
    """

    username: typing.Optional[str] = pydantic.Field(default=None)
    """
    Username or email for login (plain text)
    """

    password_secret_name: typing.Optional[str] = pydantic.Field(default=None)
    """
    Select password secret from Environment Variables
    """

    translated_steps: typing.Optional[typing.List[GuidedStep]] = pydantic.Field(default=None)
    """
    LLM-translated steps. Leave empty to auto-generate from instructions.
    """

    healed_steps: typing.Optional[typing.List[HealedStep]] = pydantic.Field(default=None)
    """
    Steps that were auto-fixed during previous runs
    """

    parse_pdfs: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Extract text from downloaded PDFs using OCR
    """

    max_pdfs: typing.Optional[int] = pydantic.Field(default=None)
    """
    Maximum number of PDFs to download and process
    """

    credentials: typing.Optional[typing.List[CredentialMapping]] = pydantic.Field(default=None)
    """
    (Deprecated) Use requires_login/username/password_secret_name instead
    """

    record_video: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Record browser session for debugging (increases execution time)
    """

    mode: typing.Optional[SourceSyncGuidedCrawlSettingsInputMode] = pydantic.Field(default=None)
    """
    Merge: upsert documents keying off site url. Replace: merge and remove stale documents.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
