class AyuelAction {
  final String label;
  final String type; // confirm, defer, regenerate

  AyuelAction({required this.label, required this.type});

  Map<String, dynamic> toMap() => {'label': label, 'type': type};

  factory AyuelAction.fromMap(Map<String, dynamic> map) {
    return AyuelAction(
      label: map['label'] ?? '',
      type: map['type'] ?? 'confirm',
    );
  }
}

class AyuelResponse {
  final String category;
  final String title;
  final String suggestion;
  final String why;
  final List<AyuelAction> actions;

  AyuelResponse({
    required this.category,
    required this.title,
    required this.suggestion,
    required this.why,
    required this.actions,
  });

  Map<String, dynamic> toMap() {
    return {
      'category': category,
      'title': title,
      'suggestion': suggestion,
      'why': why,
      'actions': actions.map((x) => x.toMap()).toList(),
    };
  }

  factory AyuelResponse.fromMap(Map<String, dynamic> map) {
    return AyuelResponse(
      category: map['category'] ?? 'General',
      title: map['title'] ?? 'Here is an idea',
      suggestion: map['suggestion'] ?? '',
      why: map['why'] ?? '',
      actions: List<AyuelAction>.from(
        (map['actions'] as List? ?? []).map((x) => AyuelAction.fromMap(x)),
      ),
    );
  }
}
