import 'package:equatable/equatable.dart'; import 'package:flux/core/utils/extensions.dart'; import 'package:flux/features/attachments/models/attachment_model.dart'; class CustomerModel extends Equatable { final String? id; // Bigint in SQL final DateTime? createdAt; final String name; final String phoneNumber; final String email; final String note; final DateTime? lastContactDate; final bool doNotDisturb; final String companyId; // UUID final bool isActive; final List attachments; const CustomerModel({ this.id, this.createdAt, required this.name, required this.phoneNumber, required this.email, required this.note, this.lastContactDate, this.doNotDisturb = false, required this.companyId, this.isActive = true, this.attachments = const [], }); @override List get props => [ id, createdAt, name, phoneNumber, email, note, lastContactDate, doNotDisturb, companyId, isActive, attachments, ]; CustomerModel copyWith({ String? id, DateTime? createdAt, String? name, String? phoneNumber, String? email, String? note, DateTime? lastContactDate, bool? doNotDisturb, String? companyId, bool? isActive, List? attachments, }) { return CustomerModel( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, name: name ?? this.name, phoneNumber: phoneNumber ?? this.phoneNumber, email: email ?? this.email, note: note ?? this.note, lastContactDate: lastContactDate ?? this.lastContactDate, doNotDisturb: doNotDisturb ?? this.doNotDisturb, companyId: companyId ?? this.companyId, isActive: isActive ?? this.isActive, attachments: attachments ?? this.attachments, ); } factory CustomerModel.fromMap(Map map) { return CustomerModel( id: map['id'] as String, createdAt: map['created_at'] != null ? DateTime.parse(map['created_at']) : null, name: (map['name'] as String).myFormat(), phoneNumber: map['phone_number'], email: map['email'], note: map['note'] ?? '', lastContactDate: map['last_contact_date'] != null ? DateTime.parse(map['last_contact_date']) : null, doNotDisturb: map['do_not_disturb'] ?? false, companyId: map['company_id'] as String, isActive: map['is_active'] ?? true, ); } Map toJson() { return { if (id != null) 'id': id, 'name': name.toLowerCase().trim(), 'phone_number': phoneNumber, 'email': email.toLowerCase().trim(), 'note': note, if (lastContactDate != null) 'last_contact_date': lastContactDate!.toIso8601String(), 'do_not_disturb': doNotDisturb, 'company_id': companyId, 'is_active': isActive, }; } }