import 'package:aitrainer_app/model/tutorial_step.dart';

enum TutorialEnum { basic, development, training }

class Tutorial {
  late int tutorialId;
  late String name;

  List<TutorialStep>? steps;

  Tutorial.fromJson(Map<String, dynamic> json) {
    this.tutorialId = json['tutorialId'];
    this.name = json['name'];

    if (json['steps'] != null && json['steps'].length > 0) {
      steps = json['steps'].map<TutorialStep>((step) => TutorialStep.fromJson(step)).toList();
      if (steps != null) {
        steps!.sort((a, b) {
          if (a.step == null || b.step == null) {
            return -1;
          } else {
            if (a.step! <= b.step!) {
              return -1;
            } else {
              return 1;
            }
          }
        });
      }
    }
  }

  Map<String, dynamic> toJson() => {'tutorialId': this.tutorialId, 'name': this.name, 'steps': steps.toString()};

  @override
  String toString() => this.toJson().toString();
}
