"""Interfaces for search API."""

from ploneintranet.core import _
from zope import schema
from zope.interface import Interface


class IPloneintranetSearchLayer(Interface):
    """Marker interface that defines a Zope 3 browser layer."""


class ISiteSearch(Interface):
    """Defines a common API for a site search utility."""

    def query(
        phrase=None,
        filters=None,
        query=None,
        start_date=None,
        end_date=None,
        start=0,
        step=None,
    ):
        """Perform a query with the given `phrase` and options.

        At least one of 'phrase' or 'filters' must be provided.

        :param phrase: The phrase to search for.
        :type phrase: str
        :param filters: A mapping of names and values to filter results by.
        :type filters: dict
        :param start_date: Earliest modified date for results.
        :type start_date: datetime.datetime
        :param end_date: Most recent modified date for results.
        :type end_date: datetime.datetime
        :param start: The offset position in results to start from.
        :type start: int
        :param step: The maximum number of results to return.
        :type step: int
        :returns: The results as a `SearchResponse` object.
        :rtype: `SearchResponse`
        """


class ISearchResult(Interface):
    """Defines a common API for search results."""

    title = schema.TextLine(title=_("The title of this search result"))

    description = schema.TextLine(title=_("The description of this search result"))

    contact_email = schema.TextLine(
        title=_("A contact email address for this search result")
    )

    contact_telephone = schema.TextLine(
        title=_("The description of this search result")
    )

    portal_type = schema.TextLine(title=_("The portal type of this search result"))

    friendly_type_name = schema.TextLine(
        title=_("The friendly label for the type of search result")
    )

    highlighted_summary = schema.Text(
        title=_("A highlighted summary of this search result")
    )

    preview_image_path = schema.ASCIILine(
        title=_(
            "The relative path to a preview image" "representing this search result"
        )
    )

    preview_image_url = schema.ASCIILine(
        title=_("The absolute URL for a preview image " "representing search result")
    )

    path = schema.ASCIILine(
        title=_("The relative path to the content for this search result")
    )

    url = schema.ASCIILine(
        title=_(
            "The absolute URL to the content for this search result "
            "based on the path and the host in the current request"
        )
    )


class ISearchResponse(Interface):
    """Defines a common API for search query responses."""

    spell_corrected_search = schema.TextLine(title=_("Spell corrected search string"))

    facets = schema.Dict(title=_("A dictionary of facets and available values"))

    total_results = schema.Int(
        title=_("The total number of results generated from the query")
    )

    def __bool__():
        """Search responses should be false if we have no results"""

    def __len__():
        """Search responses should have a length"""

    def __iter__():
        """Search responses should implement the `Iterable` protocol.

        Iteratating over this object should yield search results.
        """


class IExcludeFromSearchResults(Interface):
    """Marker interface for content that should not be listed in search results."""
