import 'package:get/get.dart';
import 'package:vitalapp/architecture/defines.dart';
import 'package:vitalapp/architecture/utils/nums.dart';

class WaistState {
  final RxnDouble _waistline = RxnDouble();
  final RxnDouble _hipline = RxnDouble();

  /// 腰围
  double? get waistline => _waistline.value;
  set waistline(double? val) => _waistline.updateValue(val);

  /// 臀围
  double? get hipline => _hipline.value;
  set hipline(double? val) => _hipline.updateValue(val);

  /// 腰臀比
  double? get whr {
    if (waistline == null || hipline == null) {
      return null;
    }
    if (hipline == 0) {
      // 0不可被除
      return 0;
    }
    final val = waistline! / hipline!;
    return double.parse(val.toStringAsFixed(2));
  }

  /// 腰围外显
  String get waistlineDisplay => NumUtils.displayDouble(waistline, "--");

  /// 臀围外显
  String get hiplineDisplay => NumUtils.displayDouble(hipline, "--");

  /// 腰臀比外显
  String get whrDisplay => whr?.toString() ?? "--";
}
