114 lines
3.0 KiB
Dart
114 lines
3.0 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
import 'package:flux/core/utils/string_extensions.dart';
|
|
|
|
class CustomerModel extends Equatable {
|
|
final String? 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;
|
|
final int fileCount;
|
|
|
|
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,
|
|
this.fileCount = 0,
|
|
});
|
|
|
|
@override
|
|
List<Object?> get props => [
|
|
id,
|
|
createdAt,
|
|
nome,
|
|
telefono,
|
|
email,
|
|
note,
|
|
dataUltimoContatto,
|
|
nonDisturbare,
|
|
companyId,
|
|
isActive,
|
|
fileCount,
|
|
];
|
|
|
|
CustomerModel copyWith({
|
|
String? id,
|
|
DateTime? createdAt,
|
|
String? nome,
|
|
String? telefono,
|
|
String? email,
|
|
String? note,
|
|
DateTime? dataUltimoContatto,
|
|
bool? nonDisturbare,
|
|
String? companyId,
|
|
bool? isActive,
|
|
int? fileCount,
|
|
}) {
|
|
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,
|
|
fileCount: fileCount ?? this.fileCount,
|
|
);
|
|
}
|
|
|
|
factory CustomerModel.fromJson(Map<String, dynamic> json) {
|
|
int count = 0;
|
|
if (json['customer_file'] != null &&
|
|
(json['customer_file'] as List).isNotEmpty) {
|
|
count = json['customer_file'][0]['count'] ?? 0;
|
|
}
|
|
return CustomerModel(
|
|
id: json['id'] as String,
|
|
createdAt: json['created_at'] != null
|
|
? DateTime.parse(json['created_at'])
|
|
: null,
|
|
nome: (json['nome'] as String).myFormat(),
|
|
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'] as String,
|
|
isActive: json['is_active'] ?? true,
|
|
fileCount: count,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
if (id != null) 'id': id,
|
|
'nome': nome.toLowerCase(),
|
|
'telefono': telefono,
|
|
'email': email.toLowerCase(),
|
|
'note': note,
|
|
if (dataUltimoContatto != null)
|
|
'data_ultimo_contatto': dataUltimoContatto!.toIso8601String(),
|
|
'non_disturbare': nonDisturbare,
|
|
'company_id': companyId,
|
|
'is_active': isActive,
|
|
};
|
|
}
|
|
}
|