# 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.agentic.workflowinstance.v1 import api_pb2 as ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_api__pb2
from ai.stigmer.agentic.workflowinstance.v1 import io_pb2 as ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2
from ai.stigmer.commons.apiresource import io_pb2 as ai_dot_stigmer_dot_commons_dot_apiresource_dot_io__pb2


class WorkflowInstanceQueryControllerStub(object):
    """WorkflowInstanceQueryController handles read operations (Get, List, Search) for WorkflowInstance resources.

    This service provides all query operations following the Command-Query Separation pattern.
    All RPCs that read state without modifying it go through this controller.

    Authorization:
    - get: Requires get permission on the specific instance
    - getByWorkflow: Authorization handled in handler via FGA query (returns filtered instances)
    - getByReference: Custom authorization (supports flexible reference lookup)

    All operations respect owner scope visibility rules (users see only their org/identity resources).
    """

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

        Args:
            channel: A grpc.Channel.
        """
        self.get = channel.unary_unary(
                '/ai.stigmer.agentic.workflowinstance.v1.WorkflowInstanceQueryController/get',
                request_serializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2.WorkflowInstanceId.SerializeToString,
                response_deserializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_api__pb2.WorkflowInstance.FromString,
                _registered_method=True)
        self.getByWorkflow = channel.unary_unary(
                '/ai.stigmer.agentic.workflowinstance.v1.WorkflowInstanceQueryController/getByWorkflow',
                request_serializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2.GetWorkflowInstancesByWorkflowRequest.SerializeToString,
                response_deserializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2.WorkflowInstanceList.FromString,
                _registered_method=True)
        self.getByReference = channel.unary_unary(
                '/ai.stigmer.agentic.workflowinstance.v1.WorkflowInstanceQueryController/getByReference',
                request_serializer=ai_dot_stigmer_dot_commons_dot_apiresource_dot_io__pb2.ApiResourceReference.SerializeToString,
                response_deserializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_api__pb2.WorkflowInstance.FromString,
                _registered_method=True)


class WorkflowInstanceQueryControllerServicer(object):
    """WorkflowInstanceQueryController handles read operations (Get, List, Search) for WorkflowInstance resources.

    This service provides all query operations following the Command-Query Separation pattern.
    All RPCs that read state without modifying it go through this controller.

    Authorization:
    - get: Requires get permission on the specific instance
    - getByWorkflow: Authorization handled in handler via FGA query (returns filtered instances)
    - getByReference: Custom authorization (supports flexible reference lookup)

    All operations respect owner scope visibility rules (users see only their org/identity resources).
    """

    def get(self, request, context):
        """Get a single workflow instance by ID.

        Retrieves a specific WorkflowInstance using its unique resource identifier.

        Input:
        WorkflowInstanceId with the instance ID (e.g., "wfi-abc123")

        Returns:
        Complete WorkflowInstance resource with:
        - api_version, kind, metadata
        - spec (workflow_id, description, environment_refs)
        - status (audit information: created_at, updated_at, version)

        Authorization:
        Requires "get" permission on the specific WorkflowInstance.
        Field path "value" extracts the resource ID from WorkflowInstanceId wrapper.
        Verifies user has access based on:
        - Instance owner scope (organization or identity_account)
        - User's IAM policies

        Use Cases:
        - Retrieve instance configuration before executing
        - View instance details in UI
        - Fetch instance for editing/updating

        Error: PERMISSION_DENIED if user lacks get permission
        Error: NOT_FOUND if instance ID doesn't exist
        """
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')

    def getByWorkflow(self, request, context):
        """Get all instances of a specific workflow template.

        Retrieves all WorkflowInstance resources that reference a specific Workflow template.
        Useful for discovering all configured deployments of a workflow.

        Example Use Case:
        Workflow "deploy-to-cloud" (wfl-123) has instances:
        - "prod-deploy" (wfi-abc) - Production deployment with aws-prod-env
        - "staging-deploy" (wfi-def) - Staging deployment with aws-staging-env
        - "dev-deploy" (wfi-ghi) - Development deployment with aws-dev-env

        Input:
        GetWorkflowInstancesByWorkflowRequest with:
        - workflow_id: Workflow template ID to filter by
        - page_info: Pagination settings (page_size, page_token)

        Returns:
        WorkflowInstanceList with:
        - total_pages: Total number of pages available
        - entries: Array of WorkflowInstance resources in current page

        Authorization:
        Authorization is handled in handler via FGA query for authorized workflow_instance_ids,
        then filtered by workflow_id. This ensures users only see instances they have access to,
        even if the parent workflow is shared across organizations.

        Filtering:
        Results are filtered by:
        - User's organization/identity visibility
        - IAM policies
        - Owner scope rules

        Error: PERMISSION_DENIED if user lacks access to the workflow
        Error: NOT_FOUND if workflow_id doesn't exist
        """
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')

    def getByReference(self, request, context):
        """Get a workflow instance by flexible reference (ID or slug).

        Retrieves a WorkflowInstance using ApiResourceReference which supports multiple lookup methods:
        - By ID: {id: "wfi-abc123"}
        - By slug: {slug: "prod-deploy"}
        - By name: {name: "Production Deploy"}

        Input:
        ApiResourceReference with one of: id, slug, or name

        Returns:
        Complete WorkflowInstance resource matching the reference.

        Authorization:
        Uses custom authorization logic in the handler.
        Allows for flexible authorization based on reference type and context.
        Typical checks:
        - User has get permission on the resolved instance
        - Instance owner scope matches user's organization/identity

        Use Cases:
        - User-friendly lookups by slug instead of opaque IDs
        - CLI commands using human-readable names
        - API integrations using stable slugs

        Example:
        Input: ApiResourceReference{slug: "prod-deploy"}
        Output: WorkflowInstance with metadata.slug = "prod-deploy"

        Error: PERMISSION_DENIED if user lacks access
        Error: NOT_FOUND if reference doesn't resolve to an instance
        """
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')


def add_WorkflowInstanceQueryControllerServicer_to_server(servicer, server):
    rpc_method_handlers = {
            'get': grpc.unary_unary_rpc_method_handler(
                    servicer.get,
                    request_deserializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2.WorkflowInstanceId.FromString,
                    response_serializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_api__pb2.WorkflowInstance.SerializeToString,
            ),
            'getByWorkflow': grpc.unary_unary_rpc_method_handler(
                    servicer.getByWorkflow,
                    request_deserializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2.GetWorkflowInstancesByWorkflowRequest.FromString,
                    response_serializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2.WorkflowInstanceList.SerializeToString,
            ),
            'getByReference': grpc.unary_unary_rpc_method_handler(
                    servicer.getByReference,
                    request_deserializer=ai_dot_stigmer_dot_commons_dot_apiresource_dot_io__pb2.ApiResourceReference.FromString,
                    response_serializer=ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_api__pb2.WorkflowInstance.SerializeToString,
            ),
    }
    generic_handler = grpc.method_handlers_generic_handler(
            'ai.stigmer.agentic.workflowinstance.v1.WorkflowInstanceQueryController', rpc_method_handlers)
    server.add_generic_rpc_handlers((generic_handler,))
    server.add_registered_method_handlers('ai.stigmer.agentic.workflowinstance.v1.WorkflowInstanceQueryController', rpc_method_handlers)


 # This class is part of an EXPERIMENTAL API.
class WorkflowInstanceQueryController(object):
    """WorkflowInstanceQueryController handles read operations (Get, List, Search) for WorkflowInstance resources.

    This service provides all query operations following the Command-Query Separation pattern.
    All RPCs that read state without modifying it go through this controller.

    Authorization:
    - get: Requires get permission on the specific instance
    - getByWorkflow: Authorization handled in handler via FGA query (returns filtered instances)
    - getByReference: Custom authorization (supports flexible reference lookup)

    All operations respect owner scope visibility rules (users see only their org/identity resources).
    """

    @staticmethod
    def get(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.agentic.workflowinstance.v1.WorkflowInstanceQueryController/get',
            ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2.WorkflowInstanceId.SerializeToString,
            ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_api__pb2.WorkflowInstance.FromString,
            options,
            channel_credentials,
            insecure,
            call_credentials,
            compression,
            wait_for_ready,
            timeout,
            metadata,
            _registered_method=True)

    @staticmethod
    def getByWorkflow(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.agentic.workflowinstance.v1.WorkflowInstanceQueryController/getByWorkflow',
            ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2.GetWorkflowInstancesByWorkflowRequest.SerializeToString,
            ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_io__pb2.WorkflowInstanceList.FromString,
            options,
            channel_credentials,
            insecure,
            call_credentials,
            compression,
            wait_for_ready,
            timeout,
            metadata,
            _registered_method=True)

    @staticmethod
    def getByReference(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.agentic.workflowinstance.v1.WorkflowInstanceQueryController/getByReference',
            ai_dot_stigmer_dot_commons_dot_apiresource_dot_io__pb2.ApiResourceReference.SerializeToString,
            ai_dot_stigmer_dot_agentic_dot_workflowinstance_dot_v1_dot_api__pb2.WorkflowInstance.FromString,
            options,
            channel_credentials,
            insecure,
            call_credentials,
            compression,
            wait_for_ready,
            timeout,
            metadata,
            _registered_method=True)
