syntax = "proto3";

package components_catalog_data.booking_automations_configuration.com.wixpress.appservice.api.upstream.com.wixpress.bookings.automations.spi.v2;
import "wix/api/annotations.proto";
import "wix/spi/definitions.proto";
import "google/protobuf/wrappers.proto";
import "wix/api/validations.proto";
import "wix/common/spi.proto";


message BookingAutomationsConfig {
  option (.wix.api.decomposite_of) = "com.wixpress.bookings.automations.spi.v2.BookingAutomationsConfig";
  // URI where the SPI Implementer is deployed.
  .wix.common.spi.SpiBaseUri deployment_uri = 1;
  // User-friendly name of the provider.
  google.protobuf.StringValue provider_name = 2 [(.wix.api.maxLength) = 100];
  // Whether the booking automations are enabled for the app's users. Default is true.
  google.protobuf.BoolValue enabled = 3;
  // Whether to allow triggering booking automations. Default is true.
  google.protobuf.BoolValue allow_booking_automation_triggering = 4;
  // Map of booking automation triggers to the corresponding automation trigger key to use instead.
  map<string, TriggerOverride> trigger_overrides = 5 [(.wix.api.maxSize) = 50];

  /**
   * 📝 PAYLOAD FIELD OVERRIDES
   * 
   * Customize specific data fields in automation trigger payloads without
   * changing the entire trigger. This allows fine-grained data transformation.
   * 
   * KEY FORMAT: Original field name in payload (e.g., "staff_member_name")
   * VALUE: TriggerFieldOverride containing the replacement field key
   * 
   * COMMON FIELD MAPPINGS:
   * • "staff_member_name" → "host_name"
   * • "service_name" → "meeting_name"
   *
   * EXAMPLE:
   * {
   *   "staff_member_name": {
   *     "automation_trigger_field_key": "consultant_name"
   *   },
   *   "service_name": {
   *     "automation_trigger_field_key": "consultation_type"  
   *   }
   * }
   * 
   * LIMITS: Maximum 100 field overrides per field
   * NOTE: Field overrides apply to ALL triggers
   */
  map<string, TriggerFieldOverride> trigger_field_overrides = 6 [(.wix.api.maxSize) = 100];
}

// Represents an override for a booking automation trigger.
message TriggerOverride {
  // The automation trigger key to use instead of the default one for the given booking automation trigger.
  string automation_trigger_key = 1 [(wix.api.minLength) = 1, (.wix.api.maxLength) = 100];
}

/**
 * ========================================
 * FIELD OVERRIDE SPECIFICATION  
 * ========================================
 * 
 * Defines a replacement field key for granular payload data transformation.
 * Field overrides allow you to substitute specific data fields in automation
 * trigger payloads without changing the entire trigger or its behavior.
 * 
 * FIELD MAPPING FLOW:
 * 1. Booking automation triggers with standard payload
 * 2. System checks for field overrides 
 * 3. If field override exists → Replace field key with new field key
 * 4. If no override → Use original field value
 * 5. Continue with automation execution
 * 
 * TRANSFORMATION SCOPE:
 * • Applies to ALL automation triggers
 * • Only affects data payload content, not trigger behavior
 * • Preserves original trigger timing and conditions
 * • Maintains automation flow and dependencies
 * 
 * COMMON FIELD MAPPING SCENARIOS:
 * • Terminology alignment: "staff_member_name" → "host_name"
 * • Schema consistency: "service_name" → "meeting_name"
 */
message TriggerFieldOverride {
    option (.wix.api.decomposite_of) = "com.wixpress.bookings.automations.spi.v2.TriggerFieldOverride";
  /**
   * 🏷️ REPLACEMENT FIELD IDENTIFIER
   * 
   * The field key in your app's automation data schema that should be used
   * instead of the original booking automation field. This enables seamless
   * data transformation to match your app's terminology and requirements.
   * 
   * FIELD KEY REQUIREMENTS:
   * ✓ Must exist in your app's automation data schema
   * ✓ Should be compatible with the original field's data type
   * ✓ Must follow consistent naming conventions
   * ✓ Should provide meaningful business context
   * 
   * MAPPING EXAMPLES:
   * 
   * TERMINOLOGY ALIGNMENT:
   * • "host_name" (for "staff_member_name")
   * • "attendee_name" (for "client_name")
   * • "consultation_type" (for "service_name")
   * 
   * BUSINESS CONTEXT:
   * • "lead_email" (for "client_email")  
   * • "opportunity_value" (for "booking_price")
   * • "meeting_duration_minutes" (for "booking_duration")
   * 
   * INTEGRATION CONSISTENCY:
   * • "customer_contact" (for "client_email")
   * • "appointment_location" (for "booking_location")
   * • "session_datetime" (for "booking_date" + "booking_time")
   * 
   * VALIDATION:
   * • Length: 1-100 characters  
   * • Must be valid field identifier
   * • Should maintain data type compatibility
   * • Must exist in target automation schema
   */
  string automation_trigger_field_key = 1 [(wix.api.minLength) = 1, (.wix.api.maxLength) = 100];
}

/**
 * ========================================
 * 
 * Examples of available Bookings Automation Triggers:
 * - "wix_bookings-sessions_booked"    → When a session/appointment is booked
 * - "wix_bookings-booking_canceled"   → When a booking is canceled
 * - "wix_bookings-session_updated"    → When appointment/class details are updated
 * 
 * Common Configuration Patterns:
 * 
 * 1. Disable all:           { "enabled": false }
 * 2. Maintenance mode:      { "allow_booking_automation_triggering": false }
 * 3. Override specific:     Use "trigger_overrides" map
 * 4. Custom integration:    Redirect to "your_app_name-your_trigger_key"
 * 
 * BoolValue Usage:
 * - null/undefined = default behavior
 * - { value: true } = explicitly enabled  
 * - { value: false } = explicitly disabled
 */