Files
stadtbote-app/lib/model/tour_task.dart
T

163 lines
4.1 KiB
Dart

class TourTask {
late int sId;
late int type;
late String topic;
bool? opt;
bool? reenter;
int? min;
int? max;
int? maxLen;
bool? rt;
bool? track;
String? txt;
int? taskArrival;
int? taskFinWork;
List<TourEntry>? entries;
/// Auswahloptionen eines Status-Tasks (Typ 11).
List<TourChoice>? choices;
/// Eingabefelder einer Text-/Zahlen-Liste (Typ 12/13).
List<TourField>? fields;
TourTask();
factory TourTask.fromJson(Map<String, dynamic> json) {
final task = TourTask();
task.sId = json['s_id'] as int;
task.type = json['type'] as int;
task.topic = json['topic'] as String;
task.opt = json['opt'] as bool? ?? false;
task.reenter = json['reenter'] as bool? ?? false;
task.min = json['min'] as int?;
task.max = json['max'] as int?;
task.maxLen = json['max_len'] as int?;
task.rt = json['rt'] as bool?;
task.track = json['track'] as bool?;
task.txt = json['txt'] as String?;
task.taskArrival = json['task_arrival'] as int?;
task.taskFinWork = json['task_fin_work'] as int?;
task.entries = json['entries'] != null
? (json['entries'] as List<dynamic>)
.map((e) => TourEntry.fromJson(e as Map<String, dynamic>))
.toList()
: null;
task.choices = json['choices'] != null
? (json['choices'] as List<dynamic>)
.map((e) => TourChoice.fromJson(e as Map<String, dynamic>))
.toList()
: null;
task.fields = json['fields'] != null
? (json['fields'] as List<dynamic>)
.map((e) => TourField.fromJson(e as Map<String, dynamic>))
.toList()
: null;
return task;
}
Map<String, dynamic> toJson() {
return {
's_id': sId,
'type': type,
'topic': topic,
'opt': opt,
'reenter': reenter,
'min': min,
'max': max,
'max_len': maxLen,
'rt': rt,
'track': track,
'txt': txt,
'task_arrival': taskArrival,
'task_fin_work': taskFinWork,
'entries': entries?.map((e) => e.toJson()).toList(),
'choices': choices?.map((e) => e.toJson()).toList(),
'fields': fields?.map((e) => e.toJson()).toList(),
};
}
}
class TourEntry {
late int code;
late String text;
late bool queryRemark;
TourEntry();
factory TourEntry.fromJson(Map<String, dynamic> json) {
final entry = TourEntry();
entry.code = json['code'] as int;
entry.text = json['text'] as String;
entry.queryRemark = json['query_remark'] as bool? ?? false;
return entry;
}
Map<String, dynamic> toJson() {
return {
'code': code,
'text': text,
'query_remark': queryRemark,
};
}
}
/// Eine Auswahloption eines Status-Tasks (Typ 11). Entspricht {@code Choice}
/// im App-JSON (txt, ret, term, quest, action, price).
class TourChoice {
late String txt;
late int ret;
bool? term;
String? quest;
String? action;
String? price;
TourChoice();
factory TourChoice.fromJson(Map<String, dynamic> json) {
final choice = TourChoice();
choice.txt = json['txt'] as String? ?? '';
choice.ret = json['ret'] as int? ?? 0;
choice.term = json['term'] as bool?;
choice.quest = json['quest'] as String?;
choice.action = json['action'] as String?;
choice.price = json['price'] as String?;
return choice;
}
Map<String, dynamic> toJson() {
return {
'txt': txt,
'ret': ret,
'term': term,
'quest': quest,
'action': action,
'price': price,
};
}
/// Ob nach Auswahl dieser Option eine zusätzliche Bemerkung erfragt wird.
bool get requiresRemark => (quest != null && quest!.trim().isNotEmpty);
}
/// Ein Eingabefeld einer Text-/Zahlen-Liste (Typ 12/13).
class TourField {
String? title;
String? placeholder;
TourField();
factory TourField.fromJson(Map<String, dynamic> json) {
final field = TourField();
field.title = json['title'] as String?;
field.placeholder = json['placeholder'] as String?;
return field;
}
Map<String, dynamic> toJson() {
return {
'title': title,
'placeholder': placeholder,
};
}
}