2026-04-10 10:47:56 +02:00
|
|
|
import 'package:equatable/equatable.dart';
|
2026-04-13 10:37:12 +02:00
|
|
|
import 'package:flux/core/utils/string_extensions.dart';
|
2026-04-20 16:52:20 +02:00
|
|
|
import 'package:flux/features/customers/models/customer_file_model.dart';
|
2026-04-10 10:47:56 +02:00
|
|
|
|
|
|
|
|
class CustomerModel extends Equatable {
|
2026-04-11 12:40:03 +02:00
|
|
|
final String? id; // Bigint in SQL
|
2026-04-10 10:47:56 +02:00
|
|
|
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;
|
2026-04-20 16:52:20 +02:00
|
|
|
final List<CustomerFileModel> files;
|
2026-04-10 10:47:56 +02:00
|
|
|
|
|
|
|
|
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,
|
2026-04-20 16:52:20 +02:00
|
|
|
this.files = const [],
|
2026-04-10 10:47:56 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
List<Object?> get props => [
|
|
|
|
|
id,
|
|
|
|
|
createdAt,
|
|
|
|
|
nome,
|
|
|
|
|
telefono,
|
|
|
|
|
email,
|
|
|
|
|
note,
|
|
|
|
|
dataUltimoContatto,
|
|
|
|
|
nonDisturbare,
|
|
|
|
|
companyId,
|
|
|
|
|
isActive,
|
2026-04-20 16:52:20 +02:00
|
|
|
files,
|
2026-04-10 10:47:56 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
CustomerModel copyWith({
|
2026-04-11 12:40:03 +02:00
|
|
|
String? id,
|
2026-04-10 10:47:56 +02:00
|
|
|
DateTime? createdAt,
|
|
|
|
|
String? nome,
|
|
|
|
|
String? telefono,
|
|
|
|
|
String? email,
|
|
|
|
|
String? note,
|
|
|
|
|
DateTime? dataUltimoContatto,
|
|
|
|
|
bool? nonDisturbare,
|
|
|
|
|
String? companyId,
|
|
|
|
|
bool? isActive,
|
2026-04-20 16:52:20 +02:00
|
|
|
List<CustomerFileModel>? files,
|
2026-04-10 10:47:56 +02:00
|
|
|
}) {
|
|
|
|
|
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,
|
2026-04-20 16:52:20 +02:00
|
|
|
files: files ?? this.files,
|
2026-04-10 10:47:56 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 16:52:20 +02:00
|
|
|
factory CustomerModel.fromMap(Map<String, dynamic> map) {
|
2026-04-10 10:47:56 +02:00
|
|
|
return CustomerModel(
|
2026-04-20 16:52:20 +02:00
|
|
|
id: map['id'] as String,
|
|
|
|
|
createdAt: map['created_at'] != null
|
|
|
|
|
? DateTime.parse(map['created_at'])
|
2026-04-10 10:47:56 +02:00
|
|
|
: null,
|
2026-04-20 16:52:20 +02:00
|
|
|
nome: (map['nome'] as String).myFormat(),
|
|
|
|
|
telefono: map['telefono'],
|
|
|
|
|
email: map['email'],
|
|
|
|
|
note: map['note'] ?? '',
|
|
|
|
|
dataUltimoContatto: map['data_ultimo_contatto'] != null
|
|
|
|
|
? DateTime.parse(map['data_ultimo_contatto'])
|
2026-04-10 10:47:56 +02:00
|
|
|
: null,
|
2026-04-20 16:52:20 +02:00
|
|
|
nonDisturbare: map['non_disturbare'] ?? false,
|
|
|
|
|
companyId: map['company_id'] as String,
|
|
|
|
|
isActive: map['is_active'] ?? true,
|
|
|
|
|
files:
|
|
|
|
|
(map['customer_file'] as List?)
|
|
|
|
|
?.map((x) => CustomerFileModel.fromMap(x))
|
|
|
|
|
.toList() ??
|
|
|
|
|
const [],
|
2026-04-10 10:47:56 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
|
return {
|
|
|
|
|
if (id != null) 'id': id,
|
2026-04-13 10:43:22 +02:00
|
|
|
'nome': nome.toLowerCase().trim(),
|
2026-04-10 10:47:56 +02:00
|
|
|
'telefono': telefono,
|
2026-04-13 10:43:22 +02:00
|
|
|
'email': email.toLowerCase().trim(),
|
2026-04-10 10:47:56 +02:00
|
|
|
'note': note,
|
|
|
|
|
if (dataUltimoContatto != null)
|
|
|
|
|
'data_ultimo_contatto': dataUltimoContatto!.toIso8601String(),
|
|
|
|
|
'non_disturbare': nonDisturbare,
|
|
|
|
|
'company_id': companyId,
|
|
|
|
|
'is_active': isActive,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|