abstract final class CpsSliderHelpers {
  static (double min, double max, double step) mappedRange(String functionCode) {
    final (defaultMin, defaultMax) = sliderRange(functionCode);
    final defaultDivdidend = dividendOfRange(functionCode);
    return switch (functionCode) {
      'static_max_dis' => (0, 500, 50),
      'presence_reference' => (0, 255, 5),
      'moving_reference' => (0, 255, 5),
      'perceptual_boundary' => (0, 500, 50),
      'moving_boundary' => (0, 500, 50),
      'moving_rigger_time' => (0, 2000, 100),
      'moving_static_time' => (0, 60000, 1000),
      'none_body_time' => (0, 300000, 5000),
      'moving_max_dis' => (0, 500, 50),
      'moving_range' => (0, 255, 5),
      'presence_range' => (0, 255, 5),
      _ => (defaultMin, defaultMax, defaultDivdidend),
    };
  }

  static (double min, double max) sliderRange(String functionCode) =>
      switch (functionCode) {
        'moving_speed' => (0, 32),
        'sensitivity' => (0, 10),
        'space_static_val' => (0, 255),
        'space_move_val' => (0, 255),
        'moving_max_dis' => (0, 10),
        'static_max_dis' => (0, 10),
        'moving_range' => (0, 25.5),
        'presence_range' => (0, 25.5),
        'presence_judgement_threshold' => (0, 255),
        'motion_amplitude_trigger_threshold' => (0, 255),
        'perceptual_boundary' => (0, 5),
        'moving_boundary' => (0, 5),
        'moving_rigger_time' => (0, 2),
        'moving_static_time' => (0, 50),
        'none_body_time' => (0, 300),
        'sports_para' => (0, 100),
        _ => (0, 300),
      };

  static double dividendOfRange(String functionCode) => switch (functionCode) {
        'presence_reference' => 5,
        'moving_reference' => 5,
        'moving_max_dis' => 0.5,
        'static_max_dis' => 0.5,
        'moving_range' => 0.1,
        'presence_range' => 0.1,
        'perceptual_boundary' => 0.5,
        'moving_boundary' => 0.5,
        'moving_rigger_time' => 0.1,
        'moving_static_time' => 1.0,
        'none_body_time' => 5.0,
        _ => 1,
      };

  static String unit(String functionCode) => switch (functionCode) {
        'moving_max_dis' ||
        'static_max_dis' ||
        'moving_range' ||
        'presence_range' ||
        'perceptual_boundary' ||
        'moving_boundary' =>
          'M',
        'moving_rigger_time' || 'moving_static_time' || 'none_body_time' => 'sec',
        _ => '',
      };

  static String displayText({
    required dynamic value,
    required String functionCode,
  }) {
    final parsedValue = double.tryParse('$value');

    return switch (functionCode) {
      'moving_max_dis' ||
      'static_max_dis' ||
      'moving_range' ||
      'presence_range' ||
      'perceptual_boundary' ||
      'moving_boundary' =>
        parsedValue?.toStringAsFixed(1) ?? '0',
      'moving_rigger_time' => parsedValue?.toStringAsFixed(2) ?? '0',
      'moving_static_time' ||
      'none_body_time' =>
        parsedValue?.toStringAsFixed(2) ?? '0',
      _ => '${parsedValue?.toStringAsFixed(0) ?? 0}',
    };
  }
}
