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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.domain_code import DomainCode
from ..types.drug_safety_check_response import DrugSafetyCheckResponse
from ..types.metadata_response import MetadataResponse
from ..types.patient_profile import PatientProfile
from .raw_client import AsyncRawDrugSafetyClient, RawDrugSafetyClient
from .types.drug_safety_check_request_lang import DrugSafetyCheckRequestLang
from .types.get_drug_safety_health_response import GetDrugSafetyHealthResponse

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


class DrugSafetyClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawDrugSafetyClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawDrugSafetyClient
        """
        return self._raw_client

    def check(
        self,
        *,
        drugs: typing.Sequence[str],
        patient_profile: typing.Optional[PatientProfile] = OMIT,
        include: typing.Optional[typing.Sequence[DomainCode]] = OMIT,
        lang: typing.Optional[DrugSafetyCheckRequestLang] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DrugSafetyCheckResponse:
        """
        Screen one or more drugs across six safety domains in a single request.

        The API resolves drug names via fuzzy matching, runs all requested safety
        checks in parallel, and returns a unified response with alerts bubbled to
        the top for easy triage.

        **Typical response time:** ~40ms (warm cache, 3 drugs, all domains).

        Parameters
        ----------
        drugs : typing.Sequence[str]
            Drug names to screen. Accepts trade names (e.g., "Augmentin 1g"),
            generic names (e.g., "amoxicillin"), or partial matches.
            Fuzzy matching resolves names to SafeRx product IDs.

            - **Free/Pro tier:** max 20 drugs per request
            - **Enterprise tier:** max 50 drugs per request

        patient_profile : typing.Optional[PatientProfile]

        include : typing.Optional[typing.Sequence[DomainCode]]
            Safety domains to check. Omit to run all six domains.
            Including fewer domains reduces response size and may improve latency.

        lang : typing.Optional[DrugSafetyCheckRequestLang]
            Response language. Controls bilingual fields such as rationale text,
            drug name translations, and clinical advice.

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

        Returns
        -------
        DrugSafetyCheckResponse
            Successful safety check

        Examples
        --------
        from saferx import SafeRxClient

        client = SafeRxClient(
            api_key="YOUR_API_KEY",
        )
        client.drug_safety.check(
            drugs=["Augmentin 1g", "Glucophage 500mg", "Marivan"],
            lang="en",
        )
        """
        _response = self._raw_client.check(
            drugs=drugs, patient_profile=patient_profile, include=include, lang=lang, request_options=request_options
        )
        return _response.data

    def get_metadata(self, *, request_options: typing.Optional[RequestOptions] = None) -> MetadataResponse:
        """
        Returns available populations, conditions, database versions, risk level
        scales, and current tier limits.

        Use this endpoint to:
        - Populate dropdown menus with valid population and condition values
        - Check database versions and coverage statistics
        - Verify your tier and rate limits
        - Cache metadata locally (changes infrequently — safe to cache for 24 hours)

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

        Returns
        -------
        MetadataResponse
            Metadata response

        Examples
        --------
        from saferx import SafeRxClient

        client = SafeRxClient(
            api_key="YOUR_API_KEY",
        )
        client.drug_safety.get_metadata()
        """
        _response = self._raw_client.get_metadata(request_options=request_options)
        return _response.data

    def get_drug_safety_health(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetDrugSafetyHealthResponse:
        """
        Returns health status of the Drug Safety API subsystem including
        overall system health and availability.

        No authentication required. Designed for monitoring services.

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

        Returns
        -------
        GetDrugSafetyHealthResponse
            Health status

        Examples
        --------
        from saferx import SafeRxClient

        client = SafeRxClient(
            api_key="YOUR_API_KEY",
        )
        client.drug_safety.get_drug_safety_health()
        """
        _response = self._raw_client.get_drug_safety_health(request_options=request_options)
        return _response.data


class AsyncDrugSafetyClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawDrugSafetyClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawDrugSafetyClient
        """
        return self._raw_client

    async def check(
        self,
        *,
        drugs: typing.Sequence[str],
        patient_profile: typing.Optional[PatientProfile] = OMIT,
        include: typing.Optional[typing.Sequence[DomainCode]] = OMIT,
        lang: typing.Optional[DrugSafetyCheckRequestLang] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DrugSafetyCheckResponse:
        """
        Screen one or more drugs across six safety domains in a single request.

        The API resolves drug names via fuzzy matching, runs all requested safety
        checks in parallel, and returns a unified response with alerts bubbled to
        the top for easy triage.

        **Typical response time:** ~40ms (warm cache, 3 drugs, all domains).

        Parameters
        ----------
        drugs : typing.Sequence[str]
            Drug names to screen. Accepts trade names (e.g., "Augmentin 1g"),
            generic names (e.g., "amoxicillin"), or partial matches.
            Fuzzy matching resolves names to SafeRx product IDs.

            - **Free/Pro tier:** max 20 drugs per request
            - **Enterprise tier:** max 50 drugs per request

        patient_profile : typing.Optional[PatientProfile]

        include : typing.Optional[typing.Sequence[DomainCode]]
            Safety domains to check. Omit to run all six domains.
            Including fewer domains reduces response size and may improve latency.

        lang : typing.Optional[DrugSafetyCheckRequestLang]
            Response language. Controls bilingual fields such as rationale text,
            drug name translations, and clinical advice.

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

        Returns
        -------
        DrugSafetyCheckResponse
            Successful safety check

        Examples
        --------
        import asyncio

        from saferx import AsyncSafeRxClient

        client = AsyncSafeRxClient(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.drug_safety.check(
                drugs=["Augmentin 1g", "Glucophage 500mg", "Marivan"],
                lang="en",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.check(
            drugs=drugs, patient_profile=patient_profile, include=include, lang=lang, request_options=request_options
        )
        return _response.data

    async def get_metadata(self, *, request_options: typing.Optional[RequestOptions] = None) -> MetadataResponse:
        """
        Returns available populations, conditions, database versions, risk level
        scales, and current tier limits.

        Use this endpoint to:
        - Populate dropdown menus with valid population and condition values
        - Check database versions and coverage statistics
        - Verify your tier and rate limits
        - Cache metadata locally (changes infrequently — safe to cache for 24 hours)

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

        Returns
        -------
        MetadataResponse
            Metadata response

        Examples
        --------
        import asyncio

        from saferx import AsyncSafeRxClient

        client = AsyncSafeRxClient(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.drug_safety.get_metadata()


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

    async def get_drug_safety_health(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetDrugSafetyHealthResponse:
        """
        Returns health status of the Drug Safety API subsystem including
        overall system health and availability.

        No authentication required. Designed for monitoring services.

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

        Returns
        -------
        GetDrugSafetyHealthResponse
            Health status

        Examples
        --------
        import asyncio

        from saferx import AsyncSafeRxClient

        client = AsyncSafeRxClient(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.drug_safety.get_drug_safety_health()


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