import 'package:flutter/material.dart';
import '../domain/inventory_adjustment_result.dart';

/// Shows a [SnackBar] reflecting the outcome of an inventory write action.
///
/// Displays a success message when [result.success] is true, or an error
/// message (with optional detail) when it is false.
void showInventoryActionSnackBar(
  BuildContext context,
  InventoryAdjustmentResult result, {
  String successMessage = 'Quantity updated.',
}) {
  if (!context.mounted) return;

  final isSuccess = result.success;
  final message = isSuccess
      ? successMessage
      : 'Update failed.${result.errorMessage != null ? ' ${result.errorMessage}' : ''}';

  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(
      content: Text(message),
      backgroundColor: isSuccess ? Colors.green.shade700 : Colors.red.shade700,
      behavior: SnackBarBehavior.floating,
      duration: const Duration(seconds: 3),
    ),
  );
}
