From 79d641bb33d48311725493c09f664361f80950c8 Mon Sep 17 00:00:00 2001 From: mark-cachy Date: Wed, 15 Apr 2026 14:43:38 +0200 Subject: [PATCH] Feat - created Services models --- .../services/models/energy_service_model.dart | 72 +++++++++ .../models/entertainment_service_model.dart | 70 +++++++++ .../services/models/fin_service_model.dart | 57 +++++++ .../services/models/service_model.dart | 146 ++++++++++++++++++ 4 files changed, 345 insertions(+) create mode 100644 lib/features/services/models/energy_service_model.dart create mode 100644 lib/features/services/models/entertainment_service_model.dart create mode 100644 lib/features/services/models/fin_service_model.dart create mode 100644 lib/features/services/models/service_model.dart diff --git a/lib/features/services/models/energy_service_model.dart b/lib/features/services/models/energy_service_model.dart new file mode 100644 index 0000000..a0e8547 --- /dev/null +++ b/lib/features/services/models/energy_service_model.dart @@ -0,0 +1,72 @@ +import 'package:equatable/equatable.dart'; + +enum EnergyType { luce, gas } // Mappa il tuo public.energy_type + +class EnergyServiceModel extends Equatable { + final String? id; + final DateTime? createdAt; + final EnergyType type; + final DateTime expiration; + final String gestoreId; + final String? serviceId; + + const EnergyServiceModel({ + this.id, + this.createdAt, + required this.type, + required this.expiration, + required this.gestoreId, + this.serviceId, + }); + + EnergyServiceModel copyWith({ + String? id, + DateTime? createdAt, + EnergyType? type, + DateTime? expiration, + String? gestoreId, + String? serviceId, + }) { + return EnergyServiceModel( + id: id ?? this.id, + createdAt: createdAt ?? this.createdAt, + type: type ?? this.type, + expiration: expiration ?? this.expiration, + gestoreId: gestoreId ?? this.gestoreId, + serviceId: serviceId ?? this.serviceId, + ); + } + + @override + List get props => [ + id, + createdAt, + type, + expiration, + gestoreId, + serviceId, + ]; + + factory EnergyServiceModel.fromMap(Map map) { + return EnergyServiceModel( + id: map['id'], + createdAt: map['created_at'] != null + ? DateTime.parse(map['created_at']) + : null, + type: map['type'] == 'gas' ? EnergyType.gas : EnergyType.luce, + expiration: DateTime.parse(map['expiration']), + gestoreId: map['gestore_id'], + serviceId: map['service_id'], + ); + } + + Map toMap() { + return { + if (id != null) 'id': id, + 'type': type.name, // .name trasforma l'enum in 'luce' o 'gas' + 'expiration': expiration.toIso8601String(), + 'gestore_id': gestoreId, + 'service_id': serviceId, + }; + } +} diff --git a/lib/features/services/models/entertainment_service_model.dart b/lib/features/services/models/entertainment_service_model.dart new file mode 100644 index 0000000..f52de08 --- /dev/null +++ b/lib/features/services/models/entertainment_service_model.dart @@ -0,0 +1,70 @@ +import 'package:equatable/equatable.dart'; + +class EntertainmentServiceModel extends Equatable { + final String? id; + final DateTime? createdAt; + final String type; // es. Sky, DAZN, ecc. + final bool constrained; // Vincolato? + final DateTime constrainExpiration; + final String? serviceId; + + const EntertainmentServiceModel({ + this.id, + this.createdAt, + required this.type, + required this.constrained, + required this.constrainExpiration, + this.serviceId, + }); + + EntertainmentServiceModel copyWith({ + String? id, + DateTime? createdAt, + String? type, + bool? constrained, + DateTime? constrainExpiration, + String? serviceId, + }) { + return EntertainmentServiceModel( + id: id ?? this.id, + createdAt: createdAt ?? this.createdAt, + type: type ?? this.type, + constrained: constrained ?? this.constrained, + constrainExpiration: constrainExpiration ?? this.constrainExpiration, + serviceId: serviceId ?? this.serviceId, + ); + } + + @override + List get props => [ + id, + createdAt, + type, + constrained, + constrainExpiration, + serviceId, + ]; + + factory EntertainmentServiceModel.fromMap(Map map) { + return EntertainmentServiceModel( + id: map['id'], + createdAt: map['created_at'] != null + ? DateTime.parse(map['created_at']) + : null, + type: map['type'], + constrained: map['constrained'] ?? false, + constrainExpiration: DateTime.parse(map['constrain_expiration']), + serviceId: map['service_id'], + ); + } + + Map toMap() { + return { + if (id != null) 'id': id, + 'type': type, + 'constrained': constrained, + 'constrain_expiration': constrainExpiration.toIso8601String(), + 'service_id': serviceId, + }; + } +} diff --git a/lib/features/services/models/fin_service_model.dart b/lib/features/services/models/fin_service_model.dart new file mode 100644 index 0000000..9a0f776 --- /dev/null +++ b/lib/features/services/models/fin_service_model.dart @@ -0,0 +1,57 @@ +import 'package:equatable/equatable.dart'; + +class FinServiceModel extends Equatable { + final String? id; + final DateTime? createdAt; + final DateTime expiration; + final String? serviceId; + final String? modelId; // FK verso model (es. iPhone, Samsung, ecc.) + + const FinServiceModel({ + this.id, + this.createdAt, + required this.expiration, + this.serviceId, + this.modelId, + }); + + FinServiceModel copyWith({ + String? id, + DateTime? createdAt, + DateTime? expiration, + String? serviceId, + String? modelId, + }) { + return FinServiceModel( + id: id ?? this.id, + createdAt: createdAt ?? this.createdAt, + expiration: expiration ?? this.expiration, + serviceId: serviceId ?? this.serviceId, + modelId: modelId ?? this.modelId, + ); + } + + @override + List get props => [id, createdAt, expiration, serviceId, modelId]; + + factory FinServiceModel.fromMap(Map map) { + return FinServiceModel( + id: map['id'], + createdAt: map['created_at'] != null + ? DateTime.parse(map['created_at']) + : null, + expiration: DateTime.parse(map['expiration']), + serviceId: map['service_id'], + modelId: map['model_id'], + ); + } + + Map toMap() { + return { + if (id != null) 'id': id, + 'expiration': expiration.toIso8601String(), + 'service_id': serviceId, + 'model_id': modelId, + }; + } +} diff --git a/lib/features/services/models/service_model.dart b/lib/features/services/models/service_model.dart new file mode 100644 index 0000000..9a83d6b --- /dev/null +++ b/lib/features/services/models/service_model.dart @@ -0,0 +1,146 @@ +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 energyServices; + final List finServices; + final List 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? energyServices, + List? finServices, + List? 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 get props => [ + id, + createdAt, + storeId, + employeeId, + customerId, + number, + isBozza, + note, + resultOk, + al, + mnp, + nip, + unica, + telepass, + energyServices, + finServices, + entertainmentServices, + ]; + + factory ServiceModel.fromMap(Map 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 [], + ); + } +}