# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

from ai.stigmer.search.v1 import io_pb2 as ai_dot_stigmer_dot_search_dot_v1_dot_io__pb2


class SearchServiceStub(object):
    """SearchService provides unified search across all API resources.

    This is a CQRS Query Service operating on the read-side of the system.
    It queries multiple domain aggregates (Agent, Skill, McpServer, Workflow)
    and returns display-optimized projections. It does not modify state.

    Architectural Note:
    Search is cross-aggregate query infrastructure, not a domain bounded context.
    It lives in the query layer (CQRS read-side), not the domain layer.
    Therefore, it does not have an api_resource_kind option like domain services.

    Authorization Model:
    Unlike domain services that use declarative authorization options,
    SearchService handles authorization programmatically in the handler:
    1. Call FGA to get authorized resource IDs per requested kind
    2. Apply filters (org, query, exclude_public) against authorized set
    3. Return only resources the caller has can_view permission on

    Usage Patterns (all via single RPC):
    - List agents in org:    {kinds: [agent], org: "acme", query: ""}
    - Search agents:         {kinds: [agent], query: "security"}
    - Search in org:         {kinds: [agent], org: "acme", query: "security"}
    - Discover all kinds:    {kinds: [], query: "kubernetes"}
    - Discover specific:     {kinds: [agent, skill], query: "kubernetes"}
    """

    def __init__(self, channel):
        """Constructor.

        Args:
            channel: A grpc.Channel.
        """
        self.search = channel.unary_unary(
                '/ai.stigmer.search.v1.SearchService/search',
                request_serializer=ai_dot_stigmer_dot_search_dot_v1_dot_io__pb2.SearchRequest.SerializeToString,
                response_deserializer=ai_dot_stigmer_dot_search_dot_v1_dot_io__pb2.SearchResponse.FromString,
                _registered_method=True)


class SearchServiceServicer(object):
    """SearchService provides unified search across all API resources.

    This is a CQRS Query Service operating on the read-side of the system.
    It queries multiple domain aggregates (Agent, Skill, McpServer, Workflow)
    and returns display-optimized projections. It does not modify state.

    Architectural Note:
    Search is cross-aggregate query infrastructure, not a domain bounded context.
    It lives in the query layer (CQRS read-side), not the domain layer.
    Therefore, it does not have an api_resource_kind option like domain services.

    Authorization Model:
    Unlike domain services that use declarative authorization options,
    SearchService handles authorization programmatically in the handler:
    1. Call FGA to get authorized resource IDs per requested kind
    2. Apply filters (org, query, exclude_public) against authorized set
    3. Return only resources the caller has can_view permission on

    Usage Patterns (all via single RPC):
    - List agents in org:    {kinds: [agent], org: "acme", query: ""}
    - Search agents:         {kinds: [agent], query: "security"}
    - Search in org:         {kinds: [agent], org: "acme", query: "security"}
    - Discover all kinds:    {kinds: [], query: "kubernetes"}
    - Discover specific:     {kinds: [agent, skill], query: "kubernetes"}
    """

    def search(self, request, context):
        """Search resources across one or more kinds.

        This is the unified entry point for list, search, and discover operations.
        The behavior is determined by the combination of request parameters:

        | Operation | kinds     | query | org     | Behavior                              |
        |-----------|-----------|-------|---------|---------------------------------------|
        | List      | [X]       | ""    | "acme"  | All X in org, sorted by created_at    |
        | List All  | [X]       | ""    | ""      | All accessible X, sorted by created_at|
        | Search    | [X]       | "..."  | ""      | Search X by query, sorted by relevance|
        | Search Org| [X]       | "..."  | "acme"  | Search X in org, sorted by relevance  |
        | Discover  | []        | "..."  | ""      | Search all kinds, sorted by relevance |

        Sort Order:
        - With query: Results sorted by relevance score (descending)
        - Without query: Results sorted by created_at (descending, newer first)

        Authorization:
        Returns only resources the caller has can_view permission on.
        The handler queries FGA per kind to get authorized IDs, then applies filters.

        Pagination:
        Use page.num (1-indexed) and page.size to paginate results.
        Response includes total_count and total_pages for UI pagination controls.
        """
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')


def add_SearchServiceServicer_to_server(servicer, server):
    rpc_method_handlers = {
            'search': grpc.unary_unary_rpc_method_handler(
                    servicer.search,
                    request_deserializer=ai_dot_stigmer_dot_search_dot_v1_dot_io__pb2.SearchRequest.FromString,
                    response_serializer=ai_dot_stigmer_dot_search_dot_v1_dot_io__pb2.SearchResponse.SerializeToString,
            ),
    }
    generic_handler = grpc.method_handlers_generic_handler(
            'ai.stigmer.search.v1.SearchService', rpc_method_handlers)
    server.add_generic_rpc_handlers((generic_handler,))
    server.add_registered_method_handlers('ai.stigmer.search.v1.SearchService', rpc_method_handlers)


 # This class is part of an EXPERIMENTAL API.
class SearchService(object):
    """SearchService provides unified search across all API resources.

    This is a CQRS Query Service operating on the read-side of the system.
    It queries multiple domain aggregates (Agent, Skill, McpServer, Workflow)
    and returns display-optimized projections. It does not modify state.

    Architectural Note:
    Search is cross-aggregate query infrastructure, not a domain bounded context.
    It lives in the query layer (CQRS read-side), not the domain layer.
    Therefore, it does not have an api_resource_kind option like domain services.

    Authorization Model:
    Unlike domain services that use declarative authorization options,
    SearchService handles authorization programmatically in the handler:
    1. Call FGA to get authorized resource IDs per requested kind
    2. Apply filters (org, query, exclude_public) against authorized set
    3. Return only resources the caller has can_view permission on

    Usage Patterns (all via single RPC):
    - List agents in org:    {kinds: [agent], org: "acme", query: ""}
    - Search agents:         {kinds: [agent], query: "security"}
    - Search in org:         {kinds: [agent], org: "acme", query: "security"}
    - Discover all kinds:    {kinds: [], query: "kubernetes"}
    - Discover specific:     {kinds: [agent, skill], query: "kubernetes"}
    """

    @staticmethod
    def search(request,
            target,
            options=(),
            channel_credentials=None,
            call_credentials=None,
            insecure=False,
            compression=None,
            wait_for_ready=None,
            timeout=None,
            metadata=None):
        return grpc.experimental.unary_unary(
            request,
            target,
            '/ai.stigmer.search.v1.SearchService/search',
            ai_dot_stigmer_dot_search_dot_v1_dot_io__pb2.SearchRequest.SerializeToString,
            ai_dot_stigmer_dot_search_dot_v1_dot_io__pb2.SearchResponse.FromString,
            options,
            channel_credentials,
            insecure,
            call_credentials,
            compression,
            wait_for_ready,
            timeout,
            metadata,
            _registered_method=True)
