class Todo {
  final int? id;
  final String title;
  final bool completed;
  final String category;
  final String priority;
  final int? createdAt;

  Todo({
    this.id,
    required this.title,
    this.completed = false,
    this.category = 'Personal',
    this.priority = 'medium',
    this.createdAt,
  });

  Todo copyWith({
    int? id,
    String? title,
    bool? completed,
    String? category,
    String? priority,
    int? createdAt,
  }) {
    return Todo(
      id: id ?? this.id,
      title: title ?? this.title,
      completed: completed ?? this.completed,
      category: category ?? this.category,
      priority: priority ?? this.priority,
      createdAt: createdAt ?? this.createdAt,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'title': title,
      'completed': completed ? 1 : 0,
      'category': category,
      'priority': priority,
    };
  }

  factory Todo.fromMap(Map<String, dynamic> map) {
    return Todo(
      id: map['id'] as int?,
      title: map['title'] as String,
      completed: (map['completed'] as int?) == 1,
      category: map['category'] as String? ?? 'Personal',
      priority: map['priority'] as String? ?? 'medium',
      createdAt: map['created_at'] as int?,
    );
  }
}
