build method

Builds the interaction.

Creates either a GenericInteraction or ClassInteraction depending on whether a payload or data was set.

Throws ArgumentError if the ID is missing or validation fails.

Implementation

InteractionDefinition build() {
  if (_id == null) throw ArgumentError('Interaction ID is required');

  InteractionDefinition interaction;

  if (_payload != null) {
    // Create class-based interaction
    interaction = ClassInteraction<T>(
      id: _id!,
      payload: _payload as T,
      rollback: _rollback,
      timeout: _timeout,
      supportsOptimistic: _supportsOptimistic,
      priority: _priority,
      tags: _tags,
      toJsonConverter: _toJsonConverter,
    );
  } else {
    // Create generic interaction
    interaction = GenericInteraction(
      id: _id!,
      data: _data,
      rollback: _rollback,
      timeout: _timeout,
      supportsOptimistic: _supportsOptimistic,
      priority: _priority,
      tags: _tags,
    );
  }

  // Validate before returning
  if (!interaction.validate()) {
    throw ArgumentError(
        'Invalid interaction: ${interaction.getValidationErrors().join(', ')}');
  }

  return interaction;
}