2026-04-16 11:50:29 +02:00
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
|
|
|
|
|
|
class ProviderModel extends Equatable {
|
2026-04-16 12:13:18 +02:00
|
|
|
final String? id;
|
2026-04-16 11:50:29 +02:00
|
|
|
final String nome;
|
|
|
|
|
final bool telefoniaFissa;
|
|
|
|
|
final bool telefoniaMobile;
|
|
|
|
|
final bool energia;
|
|
|
|
|
final bool assicurazioni;
|
|
|
|
|
final bool intrattenimento;
|
|
|
|
|
final bool altro;
|
|
|
|
|
final bool isActive;
|
|
|
|
|
final String companyId;
|
2026-04-16 19:25:42 +02:00
|
|
|
final int storesCount;
|
2026-04-16 11:50:29 +02:00
|
|
|
|
|
|
|
|
const ProviderModel({
|
2026-04-16 12:13:18 +02:00
|
|
|
this.id,
|
2026-04-16 11:50:29 +02:00
|
|
|
required this.nome,
|
|
|
|
|
required this.telefoniaFissa,
|
|
|
|
|
required this.telefoniaMobile,
|
|
|
|
|
required this.energia,
|
|
|
|
|
required this.assicurazioni,
|
|
|
|
|
required this.intrattenimento,
|
|
|
|
|
required this.altro,
|
|
|
|
|
required this.isActive,
|
|
|
|
|
required this.companyId,
|
2026-04-16 19:25:42 +02:00
|
|
|
this.storesCount = 0, // Numero di store associati, default a 0
|
2026-04-16 11:50:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
factory ProviderModel.fromMap(Map<String, dynamic> map) {
|
|
|
|
|
return ProviderModel(
|
|
|
|
|
id: map['id'],
|
|
|
|
|
nome: map['nome'],
|
|
|
|
|
telefoniaFissa: map['telefonia_fissa'] ?? false,
|
|
|
|
|
telefoniaMobile: map['telefonia_mobile'] ?? false,
|
|
|
|
|
energia: map['energia'] ?? false,
|
|
|
|
|
assicurazioni: map['assicurazioni'] ?? false,
|
|
|
|
|
intrattenimento: map['intrattenimento'] ?? false,
|
|
|
|
|
altro: map['altro'] ?? false,
|
|
|
|
|
isActive: map['is_active'] ?? true,
|
|
|
|
|
companyId: map['company_id'],
|
2026-04-16 19:25:42 +02:00
|
|
|
storesCount:
|
|
|
|
|
map['providers_in_stores'] != null &&
|
|
|
|
|
map['providers_in_stores'].isNotEmpty
|
|
|
|
|
? map['providers_in_stores'][0]['count'] as int
|
|
|
|
|
: 0, // Assumiamo che l'API possa restituire questo campo
|
2026-04-16 11:50:29 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
2026-04-16 12:13:18 +02:00
|
|
|
final map = {
|
2026-04-16 11:50:29 +02:00
|
|
|
'nome': nome,
|
|
|
|
|
'telefonia_fissa': telefoniaFissa,
|
|
|
|
|
'telefonia_mobile': telefoniaMobile,
|
|
|
|
|
'energia': energia,
|
|
|
|
|
'assicurazioni': assicurazioni,
|
|
|
|
|
'intrattenimento': intrattenimento,
|
|
|
|
|
'altro': altro,
|
|
|
|
|
'is_active': isActive,
|
|
|
|
|
'company_id': companyId,
|
|
|
|
|
};
|
2026-04-16 12:13:18 +02:00
|
|
|
// AGGIUNGIAMO L'ID SOLO SE NON È NULLO
|
|
|
|
|
// Senza questo, l'upsert non sa dove andare a parare
|
|
|
|
|
if (id != null) {
|
|
|
|
|
map['id'] = id!;
|
|
|
|
|
}
|
|
|
|
|
return map;
|
2026-04-16 11:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
List<Object?> get props => [
|
|
|
|
|
id,
|
|
|
|
|
nome,
|
|
|
|
|
telefoniaFissa,
|
|
|
|
|
telefoniaMobile,
|
|
|
|
|
energia,
|
|
|
|
|
assicurazioni,
|
|
|
|
|
intrattenimento,
|
|
|
|
|
altro,
|
|
|
|
|
isActive,
|
|
|
|
|
companyId,
|
2026-04-16 19:25:42 +02:00
|
|
|
storesCount,
|
2026-04-16 11:50:29 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
ProviderModel copyWith({
|
|
|
|
|
String? id,
|
|
|
|
|
String? nome,
|
|
|
|
|
bool? telefoniaFissa,
|
|
|
|
|
bool? telefoniaMobile,
|
|
|
|
|
bool? energia,
|
|
|
|
|
bool? assicurazioni,
|
|
|
|
|
bool? intrattenimento,
|
|
|
|
|
bool? altro,
|
|
|
|
|
bool? isActive,
|
|
|
|
|
String? companyId,
|
2026-04-16 19:25:42 +02:00
|
|
|
int? storesCount,
|
2026-04-16 11:50:29 +02:00
|
|
|
}) {
|
|
|
|
|
return ProviderModel(
|
|
|
|
|
id: id ?? this.id,
|
|
|
|
|
nome: nome ?? this.nome,
|
|
|
|
|
telefoniaFissa: telefoniaFissa ?? this.telefoniaFissa,
|
|
|
|
|
telefoniaMobile: telefoniaMobile ?? this.telefoniaMobile,
|
|
|
|
|
energia: energia ?? this.energia,
|
|
|
|
|
assicurazioni: assicurazioni ?? this.assicurazioni,
|
|
|
|
|
intrattenimento: intrattenimento ?? this.intrattenimento,
|
|
|
|
|
altro: altro ?? this.altro,
|
|
|
|
|
isActive: isActive ?? this.isActive,
|
|
|
|
|
companyId: companyId ?? this.companyId,
|
2026-04-16 19:25:42 +02:00
|
|
|
storesCount: storesCount ?? this.storesCount,
|
2026-04-16 11:50:29 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|