import 'package:nmea/nmea.dart';

class Gngst extends TalkerSentence {
  static const String id = 'GxGST';

  Gngst({required super.raw});

  @override
  bool get valid => super.valid && fields.length >= 9;

  String get utcOfPositionFix => _field(1);

  double get rms => _parseDouble(_field(2), fallback: 0.0);

  double get errorEllipseSemiMajorAxis =>
      _parseDouble(_field(3), fallback: 0.0);

  double get errorEllipseSemiMinorAxis =>
      _parseDouble(_field(4), fallback: 0.0);

  double get errorEllipseOrientation => _parseDouble(_field(5), fallback: 0.0);

  double get longitudeError => _parseDouble(_field(6), fallback: 0.0);

  double get latitudeError => _parseDouble(_field(7), fallback: 0.0);

  double get heightError => _parseDouble(_field(8), fallback: 0.0);

  String _field(int index) {
    if (index < 0 || index >= fields.length) return '';
    return fields[index].trim();
  }

  double _parseDouble(String value, {required double fallback}) {
    return double.tryParse(value) ?? fallback;
  }
}
