/// Exception class for handling various platform-related errors.
class TPlatformException implements Exception {
  final String code;

  TPlatformException(this.code);

  String get message {
    switch (code) {
      // Auth related platform errors
      case 'INVALID_LOGIN_CREDENTIALS':
        return 'Invalid login credentials. Please double-check your information.';
      case 'too-many-requests':
        return 'Too many requests. Please try again later.';
      case 'invalid-argument':
        return 'Invalid argument provided to the authentication method.';
      case 'invalid-password':
        return 'Incorrect password. Please try again.';
      case 'invalid-phone-number':
        return 'The provided phone number is invalid.';

      // Common platform errors
      case 'operation-not-allowed':
        return 'This operation is not allowed.';
      case 'session-cookie-expired':
      case 'session-expired':
        return 'Your session has expired. Please sign in again.';
      case 'uid-already-exists':
        return 'The provided user ID is already in use by another user.';
      case 'sign_in_failed':
      case 'sign-in-failed':
        return 'Sign-in failed. Please try again.';
      case 'network-request-failed':
        return 'Network request failed. Please check your internet connection.';
      case 'internal-error':
        return 'Internal error. Please try again later.';
      case 'invalid-verification-code':
        return 'Invalid verification code. Please enter a valid code.';
      case 'invalid-verification-id':
        return 'Invalid verification ID. Please request a new verification code.';
      case 'quota-exceeded':
        return 'Quota exceeded. Please try again later.';

      // Supabase specific platform errors
      case 'auth/redirect-cancelled':
        return 'Authentication was cancelled.';
      case 'auth/popup-blocked':
        return 'The authentication popup was blocked by your browser.';
      case 'auth/popup-closed':
        return 'The authentication popup was closed before completing the sign-in process.';
      case 'auth/unauthorized-domain':
        return 'The application domain is not authorized for this operation.';

      // Device/platform specific
      case 'network-unavailable':
        return 'No internet connection. Please check your network settings.';
      case 'unsupported-platform':
        return 'This feature is not supported on your device.';
      case 'camera-permission-denied':
        return 'Camera permission denied. Please enable camera access in settings.';
      case 'location-permission-denied':
        return 'Location permission denied. Please enable location access in settings.';
      case 'storage-permission-denied':
        return 'Storage permission denied. Please enable storage access in settings.';

      default:
        return 'An unexpected platform error occurred. Please try again.';
    }
  }
}
