import 'package:equatable/equatable.dart';

class ExpenseSplit extends Equatable {
  final String userId;
  final String userName;
  final double amount;
  final bool isPaid;
  final DateTime? paidAt;

  const ExpenseSplit({
    required this.userId,
    required this.userName,
    required this.amount,
    this.isPaid = false,
    this.paidAt,
  });

  factory ExpenseSplit.fromMap(Map<String, dynamic> map) {
    return ExpenseSplit(
      userId: map['userId'] ?? '',
      userName: map['userName'] ?? '',
      amount: (map['amount'] as num?)?.toDouble() ?? 0.0,
      isPaid: map['isPaid'] ?? false,
      paidAt: map['paidAt'] != null 
          ? DateTime.fromMillisecondsSinceEpoch(map['paidAt'])
          : null,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'userId': userId,
      'userName': userName,
      'amount': amount,
      'isPaid': isPaid,
      'paidAt': paidAt?.millisecondsSinceEpoch,
    };
  }

  ExpenseSplit copyWith({
    String? userId,
    String? userName,
    double? amount,
    bool? isPaid,
    DateTime? paidAt,
  }) {
    return ExpenseSplit(
      userId: userId ?? this.userId,
      userName: userName ?? this.userName,
      amount: amount ?? this.amount,
      isPaid: isPaid ?? this.isPaid,
      paidAt: paidAt ?? this.paidAt,
    );
  }

  @override
  List<Object?> get props => [userId, userName, amount, isPaid];
}