This commit is contained in:
2026-05-01 10:11:44 +02:00
parent 9c8576ada5
commit f8bcac51e1
48 changed files with 1187 additions and 1141 deletions

View File

@@ -2,38 +2,38 @@ import 'package:equatable/equatable.dart';
enum EnergyType { luce, gas } // Mappa il tuo public.energy_type
class EnergyServiceModel extends Equatable {
class EnergyOperationModel extends Equatable {
final String? id;
final DateTime? createdAt;
final EnergyType type;
final DateTime expiration;
final String providerId;
final String? serviceId;
final String? operationId;
const EnergyServiceModel({
const EnergyOperationModel({
this.id,
this.createdAt,
required this.type,
required this.expiration,
required this.providerId,
this.serviceId,
this.operationId,
});
EnergyServiceModel copyWith({
EnergyOperationModel copyWith({
String? id,
DateTime? createdAt,
EnergyType? type,
DateTime? expiration,
String? providerId,
String? serviceId,
String? operationId,
}) {
return EnergyServiceModel(
return EnergyOperationModel(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
type: type ?? this.type,
expiration: expiration ?? this.expiration,
providerId: providerId ?? this.providerId,
serviceId: serviceId ?? this.serviceId,
operationId: operationId ?? this.operationId,
);
}
@@ -44,11 +44,11 @@ class EnergyServiceModel extends Equatable {
type,
expiration,
providerId,
serviceId,
operationId,
];
factory EnergyServiceModel.fromMap(Map<String, dynamic> map) {
return EnergyServiceModel(
factory EnergyOperationModel.fromMap(Map<String, dynamic> map) {
return EnergyOperationModel(
id: map['id'],
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'])
@@ -56,7 +56,7 @@ class EnergyServiceModel extends Equatable {
type: map['type'] == 'gas' ? EnergyType.gas : EnergyType.luce,
expiration: DateTime.parse(map['expiration']),
providerId: map['provider_id'],
serviceId: map['service_id'],
operationId: map['operation_id'],
);
}
@@ -66,7 +66,7 @@ class EnergyServiceModel extends Equatable {
'type': type.name, // .name trasforma l'enum in 'luce' o 'gas'
'expiration': expiration.toIso8601String(),
'provider_id': providerId,
'service_id': serviceId,
'operation_id': operationId,
};
}
}

View File

@@ -1,40 +1,40 @@
import 'package:equatable/equatable.dart';
class EntertainmentServiceModel extends Equatable {
class EntertainmentOperationModel 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;
final String? operationId;
final String? providerId;
const EntertainmentServiceModel({
const EntertainmentOperationModel({
this.id,
this.createdAt,
required this.type,
required this.constrained,
required this.constrainExpiration,
this.serviceId,
this.operationId,
this.providerId,
});
EntertainmentServiceModel copyWith({
EntertainmentOperationModel copyWith({
String? id,
DateTime? createdAt,
String? type,
bool? constrained,
DateTime? constrainExpiration,
String? serviceId,
String? operationId,
String? providerId,
}) {
return EntertainmentServiceModel(
return EntertainmentOperationModel(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
type: type ?? this.type,
constrained: constrained ?? this.constrained,
constrainExpiration: constrainExpiration ?? this.constrainExpiration,
serviceId: serviceId ?? this.serviceId,
operationId: operationId ?? this.operationId,
providerId: providerId ?? this.providerId,
);
}
@@ -46,12 +46,12 @@ class EntertainmentServiceModel extends Equatable {
type,
constrained,
constrainExpiration,
serviceId,
operationId,
providerId,
];
factory EntertainmentServiceModel.fromMap(Map<String, dynamic> map) {
return EntertainmentServiceModel(
factory EntertainmentOperationModel.fromMap(Map<String, dynamic> map) {
return EntertainmentOperationModel(
id: map['id'],
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'])
@@ -59,7 +59,7 @@ class EntertainmentServiceModel extends Equatable {
type: map['type'],
constrained: map['constrained'] ?? false,
constrainExpiration: DateTime.parse(map['constrain_expiration']),
serviceId: map['service_id'],
operationId: map['operation_id'],
providerId: map['provider_id'],
);
}
@@ -70,7 +70,7 @@ class EntertainmentServiceModel extends Equatable {
'type': type,
'constrained': constrained,
'constrain_expiration': constrainExpiration.toIso8601String(),
'service_id': serviceId,
'operation_id': operationId,
'provider_id': providerId,
};
}

View File

@@ -1,51 +1,51 @@
import 'package:equatable/equatable.dart';
class FinServiceModel extends Equatable {
class FinOperationModel extends Equatable {
final String? id;
final DateTime? createdAt;
final DateTime expiration;
final String? serviceId;
final String? operationId;
final String? modelId; // FK verso model (es. iPhone, Samsung, ecc.)
final String? providerId;
const FinServiceModel({
const FinOperationModel({
this.id,
this.createdAt,
required this.expiration,
this.serviceId,
this.operationId,
this.modelId,
this.providerId,
});
FinServiceModel copyWith({
FinOperationModel copyWith({
String? id,
DateTime? createdAt,
DateTime? expiration,
String? serviceId,
String? operationId,
String? modelId,
String? providerId,
}) {
return FinServiceModel(
return FinOperationModel(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
expiration: expiration ?? this.expiration,
serviceId: serviceId ?? this.serviceId,
operationId: operationId ?? this.operationId,
modelId: modelId ?? this.modelId,
providerId: providerId ?? this.providerId,
);
}
@override
List<Object?> get props => [id, createdAt, expiration, serviceId, modelId];
List<Object?> get props => [id, createdAt, expiration, operationId, modelId];
factory FinServiceModel.fromMap(Map<String, dynamic> map) {
return FinServiceModel(
factory FinOperationModel.fromMap(Map<String, dynamic> map) {
return FinOperationModel(
id: map['id'],
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'])
: null,
expiration: DateTime.parse(map['expiration']),
serviceId: map['service_id'],
operationId: map['operation_id'],
modelId: map['model_id'],
providerId: map['provider_id'],
);
@@ -55,7 +55,7 @@ class FinServiceModel extends Equatable {
return {
if (id != null) 'id': id,
'expiration': expiration.toIso8601String(),
'service_id': serviceId,
'operation_id': operationId,
'model_id': modelId,
'provider_id': providerId,
};

View File

@@ -2,23 +2,23 @@ import 'dart:typed_data';
import 'package:equatable/equatable.dart';
class ServiceFileModel extends Equatable {
class OperationFileModel extends Equatable {
final String? id;
final DateTime? createdAt;
final String name;
final String extension;
final String storagePath;
final String serviceId;
final String operationId;
final int fileSize;
final Uint8List? localBytes;
const ServiceFileModel({
const OperationFileModel({
this.id,
this.createdAt,
required this.name,
required this.extension,
required this.storagePath,
required this.serviceId,
required this.operationId,
required this.fileSize,
this.localBytes,
});
@@ -37,30 +37,30 @@ class ServiceFileModel extends Equatable {
bool get isPdf => extension.toLowerCase().replaceAll('.', '') == 'pdf';
ServiceFileModel copyWith({
OperationFileModel copyWith({
String? id,
DateTime? createdAt,
String? name,
String? extension,
String? storagePath,
String? serviceId,
String? operationId,
int? fileSize,
Uint8List? localBytes,
}) {
return ServiceFileModel(
return OperationFileModel(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
name: name ?? this.name,
extension: extension ?? this.extension,
storagePath: storagePath ?? this.storagePath,
serviceId: serviceId ?? this.serviceId,
operationId: operationId ?? this.operationId,
fileSize: fileSize ?? this.fileSize,
localBytes: localBytes ?? this.localBytes,
);
}
factory ServiceFileModel.fromMap(Map<String, dynamic> map) {
return ServiceFileModel(
factory OperationFileModel.fromMap(Map<String, dynamic> map) {
return OperationFileModel(
id: map['id'] as String,
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'])
@@ -68,7 +68,7 @@ class ServiceFileModel extends Equatable {
name: map['name'] ?? '',
extension: map['extension'] ?? '',
storagePath: map['storage_path'] ?? '',
serviceId: map['service_id']?.toString() ?? '',
operationId: map['operation_id']?.toString() ?? '',
fileSize: map['file_size'] is int
? map['file_size']
: int.tryParse(map['file_size']?.toString() ?? '0') ?? 0,
@@ -81,7 +81,7 @@ class ServiceFileModel extends Equatable {
'name': name,
'extension': extension,
'storage_path': storagePath,
'service_id': serviceId,
'operation_id': operationId,
'file_size': fileSize,
};
}
@@ -93,7 +93,7 @@ class ServiceFileModel extends Equatable {
name,
extension,
storagePath,
serviceId,
operationId,
fileSize,
localBytes,
];

View File

@@ -1,11 +1,11 @@
import 'package:equatable/equatable.dart';
import 'package:flux/core/utils/extensions.dart';
import 'package:flux/features/operations/models/energy_service_model.dart';
import 'package:flux/features/operations/models/entertainment_service_model.dart';
import 'package:flux/features/operations/models/fin_service_model.dart';
import 'package:flux/features/operations/models/service_file_model.dart'; // <-- Aggiunto Import
import 'package:flux/features/operations/models/energy_operation_model.dart';
import 'package:flux/features/operations/models/entertainment_operation_model.dart';
import 'package:flux/features/operations/models/fin_operation_model.dart';
import 'package:flux/features/operations/models/operation_file_model.dart'; // <-- Aggiunto Import
class ServiceModel extends Equatable {
class OperationModel extends Equatable {
final String? id;
final DateTime? createdAt;
final String storeId;
@@ -26,14 +26,14 @@ class ServiceModel extends Equatable {
final int telepass;
// Moduli (Liste)
final List<EnergyServiceModel> energyServices;
final List<FinServiceModel> finServices;
final List<EntertainmentServiceModel> entertainmentServices;
final List<EnergyOperationModel> energyOperations;
final List<FinOperationModel> finOperations;
final List<EntertainmentOperationModel> entertainmentOperations;
// ALLEGATI (Aggiunto)
final List<ServiceFileModel> files;
final List<OperationFileModel> files;
const ServiceModel({
const OperationModel({
this.id,
this.createdAt,
required this.storeId,
@@ -48,15 +48,15 @@ class ServiceModel extends Equatable {
this.nip = 0,
this.unica = 0,
this.telepass = 0,
this.energyServices = const [],
this.finServices = const [],
this.entertainmentServices = const [],
this.energyOperations = const [],
this.finOperations = const [],
this.entertainmentOperations = const [],
this.files = const [], // <-- Aggiunto default vuoto
this.customerDisplayName,
required this.companyId,
});
ServiceModel copyWith({
OperationModel copyWith({
String? id,
DateTime? createdAt,
String? storeId,
@@ -71,14 +71,14 @@ class ServiceModel extends Equatable {
int? nip,
int? unica,
int? telepass,
List<EnergyServiceModel>? energyServices,
List<FinServiceModel>? finServices,
List<EntertainmentServiceModel>? entertainmentServices,
List<ServiceFileModel>? files, // <-- Aggiunto
List<EnergyOperationModel>? energyOperations,
List<FinOperationModel>? finOperations,
List<EntertainmentOperationModel>? entertainmentOperations,
List<OperationFileModel>? files, // <-- Aggiunto
String? customerDisplayName,
String? companyId,
}) {
return ServiceModel(
return OperationModel(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
storeId: storeId ?? this.storeId,
@@ -93,10 +93,10 @@ class ServiceModel extends Equatable {
nip: nip ?? this.nip,
unica: unica ?? this.unica,
telepass: telepass ?? this.telepass,
energyServices: energyServices ?? this.energyServices,
finServices: finServices ?? this.finServices,
entertainmentServices:
entertainmentServices ?? this.entertainmentServices,
energyOperations: energyOperations ?? this.energyOperations,
finOperations: finOperations ?? this.finOperations,
entertainmentOperations:
entertainmentOperations ?? this.entertainmentOperations,
files: files ?? this.files, // <-- Aggiunto
customerDisplayName: customerDisplayName ?? this.customerDisplayName,
companyId: companyId ?? this.companyId,
@@ -119,16 +119,16 @@ class ServiceModel extends Equatable {
nip,
unica,
telepass,
energyServices,
finServices,
entertainmentServices,
energyOperations,
finOperations,
entertainmentOperations,
files, // <-- Aggiunto
customerDisplayName,
companyId,
];
factory ServiceModel.fromMap(Map<String, dynamic> map) {
return ServiceModel(
factory OperationModel.fromMap(Map<String, dynamic> map) {
return OperationModel(
id: map['id'].toString(),
createdAt: map['created_at'] != null
? DateTime.parse(map['created_at'])
@@ -147,26 +147,26 @@ class ServiceModel extends Equatable {
telepass: map['telepass'] ?? 0,
// Estrazione sicura liste collegate
energyServices:
(map['energy_service'] as List?)
?.map((x) => EnergyServiceModel.fromMap(x))
energyOperations:
(map['energy_operation'] as List?)
?.map((x) => EnergyOperationModel.fromMap(x))
.toList() ??
const [],
finServices:
(map['fin_service'] as List?)
?.map((x) => FinServiceModel.fromMap(x))
finOperations:
(map['fin_operation'] as List?)
?.map((x) => FinOperationModel.fromMap(x))
.toList() ??
const [],
entertainmentServices:
(map['entertainment_service'] as List?)
?.map((x) => EntertainmentServiceModel.fromMap(x))
entertainmentOperations:
(map['entertainment_operation'] as List?)
?.map((x) => EntertainmentOperationModel.fromMap(x))
.toList() ??
const [],
// I FILE! (Assicurati che la foreign key su Supabase usi esattamente questo nome)
files:
(map['service_file'] as List?)
?.map((x) => ServiceFileModel.fromMap(x))
(map['operation_file'] as List?)
?.map((x) => OperationFileModel.fromMap(x))
.toList() ??
const [],