// SPDX-License-Identifier: Apache-2.0
// SRS-115: Unsupported/degraded platform behaviours documentation.
// Describes what is available, degraded, or unavailable per platform.

import 'dart:io' show Platform;
import 'package:flutter/foundation.dart' show kIsWeb;

/// Describes capability tier for a feature on a platform.
enum CapabilityTier { supported, degraded, unavailable }

/// A single platform capability description.
class PlatformCapability {
  final String feature;
  final String description;
  final CapabilityTier tier;

  const PlatformCapability({
    required this.feature,
    required this.description,
    required this.tier,
  });
}

/// Returns the current platform's capability matrix.
List<PlatformCapability> currentPlatformCapabilities() {
  if (kIsWeb) {
    return [
      PlatformCapability(
        feature: 'Audio',
        description: 'Web audio is not supported in the beta.',
        tier: CapabilityTier.unavailable,
      ),
    ];
  }
  if (Platform.isAndroid) {
    return _androidCapabilities();
  }
  if (Platform.isIOS) {
    return _iosCapabilities();
  }
  if (Platform.isMacOS) {
    return _macosCapabilities();
  }
  if (Platform.isWindows) {
    return _windowsCapabilities();
  }
  if (Platform.isLinux) {
    return _linuxCapabilities();
  }
  return [];
}

List<PlatformCapability> _androidCapabilities() => [
  const PlatformCapability(
    feature: 'Voice capture',
    description: 'Oboe AAudio backend; Bluetooth SCO supported.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Voice processing',
    description: 'WebRTC AEC3/NS/AGC2, VAD via Silero ONNX.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Foreground service',
    description: 'Persistent notification during active connection.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Global PTT hotkey',
    description: 'Not available on Android.',
    tier: CapabilityTier.unavailable,
  ),
  const PlatformCapability(
    feature: 'Audio device selection',
    description: 'System-managed; wired/BT/SCO automatic routing.',
    tier: CapabilityTier.degraded,
  ),
  const PlatformCapability(
    feature: 'Push-to-talk button',
    description: 'Media button / volume-key binding supported.',
    tier: CapabilityTier.supported,
  ),
];

List<PlatformCapability> _iosCapabilities() => [
  const PlatformCapability(
    feature: 'Voice capture',
    description: 'VoiceProcessingIO AudioUnit (default).',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Voice processing',
    description: 'Platform AEC/NS/AGC via VPIO.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Audio route switching',
    description:
        'Handles speaker/earpiece/Bluetooth route changes and interruptions.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Global PTT hotkey',
    description: 'Not available on iOS.',
    tier: CapabilityTier.unavailable,
  ),
  const PlatformCapability(
    feature: 'Background audio',
    description: 'Supported via AVAudioSession background mode.',
    tier: CapabilityTier.supported,
  ),
];

List<PlatformCapability> _macosCapabilities() => [
  const PlatformCapability(
    feature: 'Voice capture',
    description: 'cpal device enumeration; VoiceProcessingIO optional.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Voice processing',
    description: 'WebRTC AEC3/NS/AGC2; VPIO available on macOS.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Global PTT hotkey',
    description: 'Supported via platform-global key-binding API.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Secure storage',
    description: 'macOS Keychain.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Audio device selection',
    description: 'System audio output route picker.',
    tier: CapabilityTier.supported,
  ),
];

List<PlatformCapability> _windowsCapabilities() => [
  const PlatformCapability(
    feature: 'Voice capture',
    description: 'WASAPI via cpal.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Voice processing',
    description: 'WebRTC AEC3/NS/AGC2 with Silero VAD.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Global PTT hotkey',
    description: 'Supported via platform-global hotkey binding.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Secure storage',
    description: 'Windows Credential Manager / DPAPI.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Installer',
    description: 'MSIX packaging not yet available in beta.',
    tier: CapabilityTier.unavailable,
  ),
];

List<PlatformCapability> _linuxCapabilities() => [
  const PlatformCapability(
    feature: 'Voice capture',
    description: 'PulseAudio/ALSA via cpal.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Voice processing',
    description: 'WebRTC AEC3/NS/AGC2 with Silero VAD; no platform VPIO.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Global PTT hotkey',
    description: 'Supported via X11/Wayland global key-binding. ',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Secure storage',
    description: 'Secret Service / libsecret.',
    tier: CapabilityTier.supported,
  ),
  const PlatformCapability(
    feature: 'Desktop environment',
    description: 'DE-specific behaviour: screen locker may suspend audio.',
    tier: CapabilityTier.degraded,
  ),
];
