import 'package:cloud_firestore/cloud_firestore.dart';
import 'ayuel_response.dart';

class DecisionLog {
  final String id;
  final DateTime createdAt;
  final String transcript;
  final String category;
  final String responseTitle;
  final String suggestion;
  final String why;
  final List<AyuelAction> actions;
  final String? chosenAction;
  final String energy;

  DecisionLog({
    required this.id,
    required this.createdAt,
    required this.transcript,
    required this.category,
    required this.responseTitle,
    required this.suggestion,
    required this.why,
    required this.actions,
    this.chosenAction,
    required this.energy,
  });

  Map<String, dynamic> toMap() {
    return {
      'createdAt': Timestamp.fromDate(createdAt),
      'transcript': transcript,
      'category': category,
      'responseTitle': responseTitle,
      'suggestion': suggestion,
      'why': why,
      'actions': actions.map((x) => x.toMap()).toList(),
      'chosenAction': chosenAction,
      'energy': energy,
    };
  }

  factory DecisionLog.fromMap(Map<String, dynamic> map, String id) {
    return DecisionLog(
      id: id,
      createdAt: (map['createdAt'] as Timestamp).toDate(),
      transcript: map['transcript'] ?? '',
      category: map['category'] ?? '',
      responseTitle: map['responseTitle'] ?? '',
      suggestion: map['suggestion'] ?? '',
      why: map['why'] ?? '',
      actions: List<AyuelAction>.from(
        (map['actions'] as List? ?? []).map((x) => AyuelAction.fromMap(x)),
      ),
      chosenAction: map['chosenAction'],
      energy: map['energy'] ?? 'Okay',
    );
  }
}
