import 'package:equatable/equatable.dart'; class CustomerModel extends Equatable { final int? id; // Bigint in SQL final DateTime? createdAt; final String nome; final String telefono; final String email; final String note; final DateTime? dataUltimoContatto; final bool nonDisturbare; final String companyId; // UUID final bool isActive; const CustomerModel({ this.id, this.createdAt, required this.nome, required this.telefono, required this.email, required this.note, this.dataUltimoContatto, this.nonDisturbare = false, required this.companyId, this.isActive = true, }); @override List get props => [ id, createdAt, nome, telefono, email, note, dataUltimoContatto, nonDisturbare, companyId, isActive, ]; CustomerModel copyWith({ int? id, DateTime? createdAt, String? nome, String? telefono, String? email, String? note, DateTime? dataUltimoContatto, bool? nonDisturbare, String? companyId, bool? isActive, }) { return CustomerModel( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, nome: nome ?? this.nome, telefono: telefono ?? this.telefono, email: email ?? this.email, note: note ?? this.note, dataUltimoContatto: dataUltimoContatto ?? this.dataUltimoContatto, nonDisturbare: nonDisturbare ?? this.nonDisturbare, companyId: companyId ?? this.companyId, isActive: isActive ?? this.isActive, ); } factory CustomerModel.fromJson(Map json) { return CustomerModel( id: json['id'], createdAt: json['created_at'] != null ? DateTime.parse(json['created_at']) : null, nome: json['nome'], telefono: json['telefono'], email: json['email'], note: json['note'] ?? '', dataUltimoContatto: json['data_ultimo_contatto'] != null ? DateTime.parse(json['data_ultimo_contatto']) : null, nonDisturbare: json['non_disturbare'] ?? false, companyId: json['company_id'], isActive: json['is_active'] ?? true, ); } Map toJson() { return { if (id != null) 'id': id, 'nome': nome, 'telefono': telefono, 'email': email, 'note': note, if (dataUltimoContatto != null) 'data_ultimo_contatto': dataUltimoContatto!.toIso8601String(), 'non_disturbare': nonDisturbare, 'company_id': companyId, 'is_active': isActive, }; } }