166 lines
4.2 KiB
Dart
166 lines
4.2 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
import 'package:flux/features/services/models/energy_service_model.dart';
|
|
import 'package:flux/features/services/models/entertainment_service_model.dart';
|
|
import 'package:flux/features/services/models/fin_service_model.dart';
|
|
|
|
class ServiceModel extends Equatable {
|
|
final String? id;
|
|
final DateTime? createdAt;
|
|
final String storeId;
|
|
final String? employeeId;
|
|
final String? customerId;
|
|
final String number;
|
|
final bool isBozza;
|
|
final String note;
|
|
final bool resultOk;
|
|
|
|
// Telefonia
|
|
final int al;
|
|
final int mnp;
|
|
final int nip;
|
|
final int unica;
|
|
final int telepass;
|
|
|
|
// Moduli (Liste)
|
|
final List<EnergyServiceModel> energyServices;
|
|
final List<FinServiceModel> finServices;
|
|
final List<EntertainmentServiceModel> entertainmentServices;
|
|
|
|
const ServiceModel({
|
|
this.id,
|
|
this.createdAt,
|
|
required this.storeId,
|
|
this.employeeId,
|
|
this.customerId,
|
|
required this.number,
|
|
this.isBozza = true,
|
|
this.note = '',
|
|
this.resultOk = true,
|
|
this.al = 0,
|
|
this.mnp = 0,
|
|
this.nip = 0,
|
|
this.unica = 0,
|
|
this.telepass = 0,
|
|
this.energyServices = const [],
|
|
this.finServices = const [],
|
|
this.entertainmentServices = const [],
|
|
});
|
|
|
|
ServiceModel copyWith({
|
|
String? id,
|
|
DateTime? createdAt,
|
|
String? storeId,
|
|
String? employeeId,
|
|
String? customerId,
|
|
String? number,
|
|
bool? isBozza,
|
|
String? note,
|
|
bool? resultOk,
|
|
int? al,
|
|
int? mnp,
|
|
int? nip,
|
|
int? unica,
|
|
int? telepass,
|
|
List<EnergyServiceModel>? energyServices,
|
|
List<FinServiceModel>? finServices,
|
|
List<EntertainmentServiceModel>? entertainmentServices,
|
|
}) {
|
|
return ServiceModel(
|
|
id: id ?? this.id,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
storeId: storeId ?? this.storeId,
|
|
employeeId: employeeId ?? this.employeeId,
|
|
customerId: customerId ?? this.customerId,
|
|
number: number ?? this.number,
|
|
isBozza: isBozza ?? this.isBozza,
|
|
note: note ?? this.note,
|
|
resultOk: resultOk ?? this.resultOk,
|
|
al: al ?? this.al,
|
|
mnp: mnp ?? this.mnp,
|
|
nip: nip ?? this.nip,
|
|
unica: unica ?? this.unica,
|
|
telepass: telepass ?? this.telepass,
|
|
energyServices: energyServices ?? this.energyServices,
|
|
finServices: finServices ?? this.finServices,
|
|
entertainmentServices:
|
|
entertainmentServices ?? this.entertainmentServices,
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [
|
|
id,
|
|
createdAt,
|
|
storeId,
|
|
employeeId,
|
|
customerId,
|
|
number,
|
|
isBozza,
|
|
note,
|
|
resultOk,
|
|
al,
|
|
mnp,
|
|
nip,
|
|
unica,
|
|
telepass,
|
|
energyServices,
|
|
finServices,
|
|
entertainmentServices,
|
|
];
|
|
|
|
factory ServiceModel.fromMap(Map<String, dynamic> map) {
|
|
return ServiceModel(
|
|
id: map['id'],
|
|
createdAt: DateTime.parse(map['created_at']),
|
|
storeId: map['store_id'],
|
|
employeeId: map['employee_id'],
|
|
customerId: map['customer_id'],
|
|
number: map['number'] ?? '',
|
|
isBozza: map['bozza'] ?? true,
|
|
note: map['note'] ?? '',
|
|
resultOk: map['result_ok'] ?? true,
|
|
al: map['al'] ?? 0,
|
|
mnp: map['mnp'] ?? 0,
|
|
nip: map['nip'] ?? 0,
|
|
unica: map['unica'] ?? 0,
|
|
telepass: map['telepass'] ?? 0,
|
|
|
|
// Mappaggio delle liste collegate (se incluse nella query)
|
|
energyServices:
|
|
(map['energy_service'] as List?)
|
|
?.map((x) => EnergyServiceModel.fromMap(x))
|
|
.toList() ??
|
|
const [],
|
|
finServices:
|
|
(map['fin_service'] as List?)
|
|
?.map((x) => FinServiceModel.fromMap(x))
|
|
.toList() ??
|
|
const [],
|
|
entertainmentServices:
|
|
(map['entertainment_service'] as List?)
|
|
?.map((x) => EntertainmentServiceModel.fromMap(x))
|
|
.toList() ??
|
|
const [],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
if (id != null) 'id': id,
|
|
'store_id': storeId,
|
|
'employee_id': employeeId,
|
|
'customer_id': customerId,
|
|
'number': number,
|
|
'bozza': isBozza,
|
|
'note': note,
|
|
'result_ok': resultOk,
|
|
'al': al,
|
|
'mnp': mnp,
|
|
'nip': nip,
|
|
'unica': unica,
|
|
'telepass': telepass,
|
|
// Le liste non le mettiamo qui perché vanno in tabelle diverse!
|
|
};
|
|
}
|
|
}
|