isAIFeatureEnabled static method

Future<void> isAIFeatureEnabled(
  1. String feature, {
  2. required dynamic onSuccess(
    1. bool isEnabled
    ),
  3. required dynamic onError(
    1. CometChatException excep
    ),
})

Check if a specific AI feature is enabled.

Migration Note: Migrated from platform channels to native Dart implementation. Uses AiRepository to check AI feature status. Behavior and signature remain identical for backward compatibility.

Android Reference: CometChat.isAIFeatureEnabled(String feature, CallbackListener<Boolean>)

Implementation

static Future<void> isAIFeatureEnabled(String feature,
    {required Function(bool isEnabled) onSuccess,
    required Function(CometChatException e) onError}) async {
  try {
    // Validate parameters
    if (feature.isEmpty) {
      onError(CometChatException(ErrorCode.errorEmptyFeature,
          ErrorMessage.errorEmptyFeature, ErrorMessage.errorEmptyFeature));
      return;
    }

    // Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // Call native Dart AI repository
    final isEnabled = await sdk.ai.isAIFeatureEnabled(feature);

    // Call success callback
    onSuccess(isEnabled);
  } on SdkException catch (sdkEx) {
    // Convert SdkException to CometChatException
    final cometChatEx = CometChatException(
      sdkEx.code,
      sdkEx.details ?? sdkEx.message,
      sdkEx.message,
    );
    onError(cometChatEx);
  } catch (e) {
    onError(CometChatException(
      ErrorCode.errorUnhandledException,
      e.toString(),
      e.toString(),
    ));
  }
}