# Plugin Metadata:
# Name: sam-event-mesh-gateway
# Version: 0.1.0
# Description: Solace Agent Mesh Gateway plugin for integrating with Solace PubSub+ event brokers.
# Author: SolaceLabs <solacelabs@solace.com>

log:
  stdout_log_level: INFO
  log_file_level: DEBUG
  log_file: em_gateway.log

# To use the `shared_config.yaml` file, uncomment the following line and remove the `shared_config` section below.
!include shared_config.yaml


apps:
  - name: event-mesh-gateway-app
    app_module: sam_event_mesh_gateway.app
    broker:
      <<: *broker_connection

    app_config:
      namespace: "${NAMESPACE}" 
      gateway_id: "event-mesh-gw-01" # Unique ID for this gateway instance

      artifact_service: *default_artifact_service
      authorization_service:
        type: "none" # Or "default_rbac"
      
      # --- Event Mesh Gateway Specific Parameters ---
      event_mesh_broker_config: # For the data plane Solace client
        broker_url: ${SOLACE_BROKER_URL} # Can be same or different from control plane
        broker_vpn: ${SOLACE_BROKER_VPN}
        broker_username: ${SOLACE_BROKER_USERNAME}
        broker_password: ${SOLACE_BROKER_PASSWORD}
        # Other data plane client settings (e.g., client_name, reconnection_strategy)

      ##############################
      # 1. UPDATE REQUIRED - START #
      ##############################
      
      event_handlers: # List of handlers for incoming Solace messages
        - name: "generic_json_event_handler"
          subscriptions:
            - topic: "test/ed/>"
              qos: 1
          input_expression: "template:Summarize this data: {{json://input.payload}}"
          payload_encoding: "utf-8"
          payload_format: "json"
          on_success: "success_response_handler"
          on_error: "error_response_handler"
          user_identity_expression: "input.user_properties:initiator_id" # Optional
          default_user_identity: "anonymous_event_mesh_user" # If no identity from event
          target_agent_name: "OrchestratorAgent" # Static target agent
          # target_agent_name_expression: "input.user_properties:target_agent" # Or dynamic
          forward_context: # Optional: Forward data from input to output handlers
            correlation_id: "input.user_properties:correlation_id" # Example: forward a correlation ID

  # Example of a second event handler, commented out
  #       - name: "text_event_to_specific_agent"
  #         subscriptions:
  #           - topic: "external/systemB/events/text/>"
  #         input_expression: "template:User query from System B: {{text://input.payload}}"
  #         payload_encoding: "utf-8" # Or "none" if payload is already string
  #         payload_format: "text"
  #         on_success: "text_response_to_systemB"
  #         target_agent_name_expression: "static:TextAnalysisAgent" # Example of static via expression

      output_handlers: # Optional: List of handlers for publishing A2A responses
        - name: "success_response_handler"
          max_file_size_for_base64_bytes: 5242880 # 5MB limit for embedded files
          topic_expression: "template:test/responses/{{text://user_data.forward_context:correlation_id}}"
          payload_expression: "task_response:text" # Use the simplified payload's text field
          payload_encoding: "utf-8"
          payload_format: "text"
          # output_schema: # Optional: Embedded JSON schema for validation
          #   type: "object"
          #   properties:
          #     processed_data: { "type": "string" }
          #   required: ["processed_data"]
          # on_validation_error: "log" # Or "drop"
        - name: "error_response_handler"
          topic_expression: "template:test/errors/{{text://user_data.forward_context:correlation_id}}"
          payload_expression: "task_response:a2a_task_response.error" # Send the full error object
          payload_encoding: "utf-8"
          payload_format: "json"


      ############################
      # 1. UPDATE REQUIRED - END #
      ############################