import 'package:flutter/services.dart';

class HapticsService {
  void trigger(String type) {
    switch (type) {
      case 'light':
        HapticFeedback.lightImpact();
        break;
      case 'medium':
        HapticFeedback.mediumImpact();
        break;
      case 'heavy':
        HapticFeedback.heavyImpact();
        break;
      case 'success':
        HapticFeedback.mediumImpact();
        Future.delayed(const Duration(milliseconds: 100), () {
          HapticFeedback.lightImpact();
        });
        break;
      case 'error':
        HapticFeedback.heavyImpact();
        Future.delayed(const Duration(milliseconds: 80), () {
          HapticFeedback.heavyImpact();
        });
        break;
      case 'selection':
        HapticFeedback.selectionClick();
        break;
      case 'dice':
        _dicePattern();
        break;
      case 'coin':
        _coinPattern();
        break;
      default:
        HapticFeedback.lightImpact();
    }
  }

  void _dicePattern() async {
    for (int i = 0; i < 3; i++) {
      HapticFeedback.selectionClick();
      await Future.delayed(const Duration(milliseconds: 60));
    }
  }

  void _coinPattern() async {
    for (int i = 0; i < 3; i++) {
      HapticFeedback.lightImpact();
      await Future.delayed(const Duration(milliseconds: 40));
    }
  }
}
