import 'dart:ui';
import 'dart:convert';

import 'package:workouttest_util/util/app_language.dart';

enum TutorialEnum { basic, development, training }

class TutorialStepAction {
  late String direction;
  late int top;
  late int left;
  late bool showBubble;
  late int bubbleX;
  late int bubbleY;
  late int bubbleWidth;
  late int bubbleHeight;
  late bool showCheckText;
  late int parent;

  TutorialStepAction.fromJson(Map json) {
    this.direction = json['direction'];
    this.top = json['top'];
    this.left = json['left'];
    this.showBubble = json['show_bubble'];
    this.bubbleX = json['bubble_x'];
    this.bubbleY = json['bubble_y'];
    this.bubbleWidth = json['bubble_width'];
    this.bubbleHeight = json['bubble_height'];
    this.showCheckText = json['show_check_text'];
    this.parent = json['parent'];
  }

  Map<String, dynamic> toJson() => {
        "direction": this.direction,
        "top": this.top,
        "left": this.left,
        "showBubble": this.showBubble,
        "bubbleX": this.bubbleX,
        "bubbleY": this.bubbleY,
        "bubbleWidth": this.bubbleWidth,
        "bubbleHeight": this.bubbleHeight,
        "showCheckText": this.showCheckText,
        "parent": this.parent,
      };

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

class TutorialStep {
  int? tutorialStepId;
  int? tutorialId;
  int? step;
  String? tutorialText;
  String? direction;
  String? checkText;
  String? condition;
  String? branch;
  int? parentId;
  TutorialStepAction? action;

  String? tutorialTextTranslation;
  String? errorTextTranslation;

  TutorialStep.fromJson(Map json) {
    this.tutorialStepId = json['tutorialStepId'];
    this.tutorialId = json['tutorialId'];
    this.step = json['step'];
    this.tutorialText = json['tutorialText'];
    this.checkText = json['checkText'];
    this.condition = json['condition'];
    if (this.condition != null) {
      this.condition = condition!.replaceAll(r'\\', "replace");
      this.action = TutorialStepAction.fromJson(jsonDecode(condition!));
    }

    if (json['translations'] != null && json['translations'].length > 0) {
      this.tutorialTextTranslation =
          AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['tutorialText'] : json['tutorialText'];
      this.errorTextTranslation = AppLanguage().appLocal == Locale('hu') ? json['translations'][0]['errorText'] : json['errorText'];
    }
  }

  Map<String, dynamic> toJson() => {
        "tutorialStepId": this.tutorialStepId,
        "tutorialId": this.tutorialId,
        "step": this.step,
        "tutorialText": this.tutorialText,
        "checkText": this.checkText,
        "tutorialTextTranslation": this.tutorialTextTranslation,
        "errorTextTranslation": this.errorTextTranslation,
        "condition": this.condition,
        "action": this.action != null ? this.action!.toJson() : ""
      };

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