import 'package:cloud_firestore/cloud_firestore.dart';

class HelpModel {
  final String id;
  final String userId;
  final String name;
  final String email;
  final String problem;
  final String? attachmentUrl;
  final DateTime createdAt;
  final String status; // pending, resolved, in_progress

  HelpModel({
    required this.id,
    required this.userId,
    required this.name,
    required this.email,
    required this.problem,
    this.attachmentUrl,
    required this.createdAt,
    this.status = 'pending',
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'userId': userId,
      'name': name,
      'email': email,
      'problem': problem,
      'attachmentUrl': attachmentUrl,
      'createdAt': createdAt,
      'status': status,
    };
  }

  factory HelpModel.fromMap(Map<String, dynamic> map) {
    return HelpModel(
      id: map['id'] as String,
      userId: map['userId'] as String,
      name: map['name'] as String,
      email: map['email'] as String,
      problem: map['problem'] as String,
      attachmentUrl: map['attachmentUrl'] as String?,
      createdAt: (map['createdAt'] as Timestamp).toDate(),
      status: map['status'] as String,
    );
  }

  HelpModel copyWith({
    String? id,
    String? userId,
    String? name,
    String? email,
    String? problem,
    String? attachmentUrl,
    DateTime? createdAt,
    String? status,
  }) {
    return HelpModel(
      id: id ?? this.id,
      userId: userId ?? this.userId,
      name: name ?? this.name,
      email: email ?? this.email,
      problem: problem ?? this.problem,
      attachmentUrl: attachmentUrl ?? this.attachmentUrl,
      createdAt: createdAt ?? this.createdAt,
      status: status ?? this.status,
    );
  }
}
