class FitnessState {
  late final String value;
  late final String stateText;
  late final String explanation;

  static String beginner = "beginner";
  static String intermediate = "intermediate";
  static String advanced = "advanced";
  static String professional = "professional";

  FitnessState({required this.value, required this.stateText, required this.explanation});

  bool isEqual(FitnessState? state) {
    if (state == null) {
      return false;
    }
    return state.value == this.value;
  }

  @override
  String toString() {
    return stateText;
  }
}

class FitnessItem {
  static final FitnessItem _singleton = FitnessItem._internal();
  List<FitnessState> elements = [];

  factory FitnessItem() {
    return _singleton;
  }

  FitnessItem._internal() {
    elements.add(FitnessState(
        value: FitnessState.beginner, stateText: _capitalize(FitnessState.beginner), explanation: "I am " + FitnessState.beginner));
    elements.add(FitnessState(
        value: FitnessState.intermediate,
        stateText: _capitalize(FitnessState.intermediate),
        explanation: "I am " + FitnessState.intermediate));
    elements.add(FitnessState(
        value: FitnessState.advanced, stateText: _capitalize(FitnessState.advanced), explanation: "I am " + FitnessState.advanced));
    elements.add(FitnessState(
        value: FitnessState.professional,
        stateText: _capitalize(FitnessState.professional),
        explanation: "I am " + FitnessState.professional));
  }

  String _capitalize(String value) {
    return "${value[0].toUpperCase()}${value.substring(1)}";
  }

  List<FitnessState> toList() => elements;

  FitnessState? getItem(String? value) {
    if (value == null || value.length == 0) {
      return elements[0];
    }
    FitnessState? selected;
    elements.forEach((element) {
      if (element.value == value) {
        selected = element;
      }
    });
    return selected;
  }
}
