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

import datetime as dt
import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.check_exists_response import CheckExistsResponse
from ..types.pipeline_success_response import PipelineSuccessResponse
from ..types.sync_operation import SyncOperation
from .raw_client import AsyncRawConnectorsDataPipelineClient, RawConnectorsDataPipelineClient
from .types.sync_request_sync_mode import SyncRequestSyncMode

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class ConnectorsDataPipelineClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawConnectorsDataPipelineClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawConnectorsDataPipelineClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawConnectorsDataPipelineClient
        """
        return self._raw_client

    def upsert_pipeline_data(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> PipelineSuccessResponse:
        """
        Accept data from data pipeline platforms for processing.

            **Authentication**: Dedicated Pipeline Connector API Key required (`X-API-Key` header)

            **Phase 1**: Validates payload and returns acknowledgment
            **Phase 2**: Will process data, generate embeddings, and store in vector store

            **Rate Limit**: 100 requests per minute per organization
            **Batch Size**: Maximum 1000 records per request

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PipelineSuccessResponse
            Batch processed successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.connectors_data_pipeline.upsert_pipeline_data()
        """
        _response = self._raw_client.upsert_pipeline_data(request_options=request_options)
        return _response.data

    def sync_pipeline_data(
        self,
        *,
        organization_id: str,
        vector_store_id: str,
        sync_mode: SyncRequestSyncMode,
        sync_timestamp: dt.datetime,
        operations: typing.Sequence[SyncOperation],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Any]:
        """
        Unified endpoint for syncing data from pipeline platforms.

            Supports both incremental and full_refresh sync modes.
            Handles upsert and delete operations atomically.

            **Processing**: The request is validated synchronously and then processed
            asynchronously in a background worker. The endpoint returns 202 Accepted
            immediately with a sync_id for tracking.

            **Authentication**: Pipeline Connector API Key required (X-API-Key header)

            **Sync Modes**:
            - `incremental`: Process only the operations provided (updates/deletes)
            - `full_refresh`: Clear all records in affected namespaces, then insert new data

            **Rate Limit**: 100 requests per minute per organization
            **Batch Size**: Maximum 5000 operations per request

        Parameters
        ----------
        organization_id : str
            Organization ID (org_ prefixed)

        vector_store_id : str
            Vector store ID (vs_ prefixed)

        sync_mode : SyncRequestSyncMode
            Sync mode: incremental (updates only) or full_refresh (complete replacement)

        sync_timestamp : dt.datetime
            ISO 8601 timestamp of sync start

        operations : typing.Sequence[SyncOperation]
            List of operations to perform

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Dict[str, typing.Any]
            Sync accepted for processing

        Examples
        --------
        import datetime

        from aitronos import Aitronos, SyncOperation

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.connectors_data_pipeline.sync_pipeline_data(
            organization_id="organization_id",
            vector_store_id="vector_store_id",
            sync_mode="incremental",
            sync_timestamp=datetime.datetime.fromisoformat(
                "2024-01-15 09:30:00+00:00",
            ),
            operations=[
                SyncOperation(
                    action="upsert",
                    namespace="namespace",
                    id="id",
                )
            ],
        )
        """
        _response = self._raw_client.sync_pipeline_data(
            organization_id=organization_id,
            vector_store_id=vector_store_id,
            sync_mode=sync_mode,
            sync_timestamp=sync_timestamp,
            operations=operations,
            request_options=request_options,
        )
        return _response.data

    def check_records_exist(
        self,
        *,
        organization_id: str,
        vector_store_id: str,
        ids: typing.Sequence[str],
        namespace: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CheckExistsResponse:
        """
        Check which records already exist to avoid duplicate processing.

            **Authentication**: Dedicated Pipeline Connector API Key required (`X-API-Key` header)

            Returns lists of existing and new IDs for efficient deduplication.

        Parameters
        ----------
        organization_id : str
            Organization ID (org_ prefixed)

        vector_store_id : str
            Vector store ID (vs_ prefixed) - each connector is tied to a specific vector store

        ids : typing.Sequence[str]
            Source system IDs to check

        namespace : str
            Namespace to check within

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CheckExistsResponse
            Check completed successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.connectors_data_pipeline.check_records_exist(
            organization_id="organization_id",
            vector_store_id="vector_store_id",
            ids=["ids"],
            namespace="namespace",
        )
        """
        _response = self._raw_client.check_records_exist(
            organization_id=organization_id,
            vector_store_id=vector_store_id,
            ids=ids,
            namespace=namespace,
            request_options=request_options,
        )
        return _response.data

    def pipeline_health(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Any]:
        """
        Health check endpoint for pipeline connector service.

            **Authentication**: None required

            Returns service status and configuration information.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Dict[str, typing.Any]
            Service is healthy

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.connectors_data_pipeline.pipeline_health()
        """
        _response = self._raw_client.pipeline_health(request_options=request_options)
        return _response.data

    def validate_pipeline_configuration(
        self,
        *,
        organization_id: str,
        vector_store_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Any]:
        """
        Validate pipeline connector configuration including vector store, organization, and API key.

            **Authentication**: Pipeline Connector API Key required (`X-API-Key` header)

            **Query Parameters**:
            - `organization_id` (required): Organization ID to validate
            - `vector_store_id` (optional): Specific vector store ID to validate

            Validates:
            - API key authentication
            - Organization exists
            - Vector store record (if vector_store_id provided)
            - Vector store service connectivity
            - Collection initialization for organization

            Returns detailed validation results for each component.

        Parameters
        ----------
        organization_id : str

        vector_store_id : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Dict[str, typing.Any]
            Configuration validation results

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.connectors_data_pipeline.validate_pipeline_configuration(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.validate_pipeline_configuration(
            organization_id=organization_id, vector_store_id=vector_store_id, request_options=request_options
        )
        return _response.data


class AsyncConnectorsDataPipelineClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawConnectorsDataPipelineClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawConnectorsDataPipelineClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawConnectorsDataPipelineClient
        """
        return self._raw_client

    async def upsert_pipeline_data(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> PipelineSuccessResponse:
        """
        Accept data from data pipeline platforms for processing.

            **Authentication**: Dedicated Pipeline Connector API Key required (`X-API-Key` header)

            **Phase 1**: Validates payload and returns acknowledgment
            **Phase 2**: Will process data, generate embeddings, and store in vector store

            **Rate Limit**: 100 requests per minute per organization
            **Batch Size**: Maximum 1000 records per request

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PipelineSuccessResponse
            Batch processed successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.connectors_data_pipeline.upsert_pipeline_data()


        asyncio.run(main())
        """
        _response = await self._raw_client.upsert_pipeline_data(request_options=request_options)
        return _response.data

    async def sync_pipeline_data(
        self,
        *,
        organization_id: str,
        vector_store_id: str,
        sync_mode: SyncRequestSyncMode,
        sync_timestamp: dt.datetime,
        operations: typing.Sequence[SyncOperation],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Any]:
        """
        Unified endpoint for syncing data from pipeline platforms.

            Supports both incremental and full_refresh sync modes.
            Handles upsert and delete operations atomically.

            **Processing**: The request is validated synchronously and then processed
            asynchronously in a background worker. The endpoint returns 202 Accepted
            immediately with a sync_id for tracking.

            **Authentication**: Pipeline Connector API Key required (X-API-Key header)

            **Sync Modes**:
            - `incremental`: Process only the operations provided (updates/deletes)
            - `full_refresh`: Clear all records in affected namespaces, then insert new data

            **Rate Limit**: 100 requests per minute per organization
            **Batch Size**: Maximum 5000 operations per request

        Parameters
        ----------
        organization_id : str
            Organization ID (org_ prefixed)

        vector_store_id : str
            Vector store ID (vs_ prefixed)

        sync_mode : SyncRequestSyncMode
            Sync mode: incremental (updates only) or full_refresh (complete replacement)

        sync_timestamp : dt.datetime
            ISO 8601 timestamp of sync start

        operations : typing.Sequence[SyncOperation]
            List of operations to perform

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Dict[str, typing.Any]
            Sync accepted for processing

        Examples
        --------
        import asyncio
        import datetime

        from aitronos import AsyncAitronos, SyncOperation

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.connectors_data_pipeline.sync_pipeline_data(
                organization_id="organization_id",
                vector_store_id="vector_store_id",
                sync_mode="incremental",
                sync_timestamp=datetime.datetime.fromisoformat(
                    "2024-01-15 09:30:00+00:00",
                ),
                operations=[
                    SyncOperation(
                        action="upsert",
                        namespace="namespace",
                        id="id",
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.sync_pipeline_data(
            organization_id=organization_id,
            vector_store_id=vector_store_id,
            sync_mode=sync_mode,
            sync_timestamp=sync_timestamp,
            operations=operations,
            request_options=request_options,
        )
        return _response.data

    async def check_records_exist(
        self,
        *,
        organization_id: str,
        vector_store_id: str,
        ids: typing.Sequence[str],
        namespace: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CheckExistsResponse:
        """
        Check which records already exist to avoid duplicate processing.

            **Authentication**: Dedicated Pipeline Connector API Key required (`X-API-Key` header)

            Returns lists of existing and new IDs for efficient deduplication.

        Parameters
        ----------
        organization_id : str
            Organization ID (org_ prefixed)

        vector_store_id : str
            Vector store ID (vs_ prefixed) - each connector is tied to a specific vector store

        ids : typing.Sequence[str]
            Source system IDs to check

        namespace : str
            Namespace to check within

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        CheckExistsResponse
            Check completed successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.connectors_data_pipeline.check_records_exist(
                organization_id="organization_id",
                vector_store_id="vector_store_id",
                ids=["ids"],
                namespace="namespace",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.check_records_exist(
            organization_id=organization_id,
            vector_store_id=vector_store_id,
            ids=ids,
            namespace=namespace,
            request_options=request_options,
        )
        return _response.data

    async def pipeline_health(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Any]:
        """
        Health check endpoint for pipeline connector service.

            **Authentication**: None required

            Returns service status and configuration information.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Dict[str, typing.Any]
            Service is healthy

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.connectors_data_pipeline.pipeline_health()


        asyncio.run(main())
        """
        _response = await self._raw_client.pipeline_health(request_options=request_options)
        return _response.data

    async def validate_pipeline_configuration(
        self,
        *,
        organization_id: str,
        vector_store_id: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Any]:
        """
        Validate pipeline connector configuration including vector store, organization, and API key.

            **Authentication**: Pipeline Connector API Key required (`X-API-Key` header)

            **Query Parameters**:
            - `organization_id` (required): Organization ID to validate
            - `vector_store_id` (optional): Specific vector store ID to validate

            Validates:
            - API key authentication
            - Organization exists
            - Vector store record (if vector_store_id provided)
            - Vector store service connectivity
            - Collection initialization for organization

            Returns detailed validation results for each component.

        Parameters
        ----------
        organization_id : str

        vector_store_id : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Dict[str, typing.Any]
            Configuration validation results

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.connectors_data_pipeline.validate_pipeline_configuration(
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.validate_pipeline_configuration(
            organization_id=organization_id, vector_store_id=vector_store_id, request_options=request_options
        )
        return _response.data
