initial commit
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
/// Modèle établissement (laverie).
|
||||
class Establishment {
|
||||
const Establishment({
|
||||
required this.uuid,
|
||||
required this.name,
|
||||
required this.address,
|
||||
this.city,
|
||||
this.zipCode,
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
this.isActive = true,
|
||||
this.machines = const [],
|
||||
});
|
||||
|
||||
final String uuid;
|
||||
final String name;
|
||||
final String address;
|
||||
final String? city;
|
||||
final String? zipCode;
|
||||
final double? latitude;
|
||||
final double? longitude;
|
||||
final bool isActive;
|
||||
final List<Machine> machines;
|
||||
|
||||
String get fullAddress {
|
||||
final parts = [address, zipCode, city].where((p) => p != null && p.isNotEmpty);
|
||||
return parts.join(', ');
|
||||
}
|
||||
|
||||
factory Establishment.fromJson(Map<String, dynamic> json) {
|
||||
final machinesJson = json['machines'] as List<dynamic>? ?? [];
|
||||
|
||||
return Establishment(
|
||||
uuid: json['uuid'] as String,
|
||||
name: json['name'] as String,
|
||||
address: json['address'] as String? ?? '',
|
||||
city: json['city'] as String?,
|
||||
zipCode: json['zip_code'] as String?,
|
||||
latitude: (json['latitude'] as num?)?.toDouble(),
|
||||
longitude: (json['longitude'] as num?)?.toDouble(),
|
||||
isActive: json['is_active'] as bool? ?? true,
|
||||
machines: machinesJson
|
||||
.map((m) => Machine.fromJson(m as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Modèle machine (lave-linge / sèche-linge).
|
||||
class Machine {
|
||||
const Machine({
|
||||
required this.uuid,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.status,
|
||||
this.qrCode,
|
||||
});
|
||||
|
||||
final String uuid;
|
||||
final String name;
|
||||
final String type;
|
||||
final String status;
|
||||
final String? qrCode;
|
||||
|
||||
bool get isAvailable => status == 'available';
|
||||
|
||||
String get typeLabel {
|
||||
switch (type) {
|
||||
case 'washer_small':
|
||||
return 'Lave-linge petit';
|
||||
case 'washer_large':
|
||||
return 'Lave-linge grand';
|
||||
case 'dryer_small':
|
||||
return 'Sèche-linge petit';
|
||||
case 'dryer_large':
|
||||
return 'Sèche-linge grand';
|
||||
default:
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
String get statusLabel {
|
||||
switch (status) {
|
||||
case 'available':
|
||||
return 'Disponible';
|
||||
case 'reserved':
|
||||
return 'Réservée';
|
||||
case 'running':
|
||||
return 'En cours';
|
||||
case 'maintenance':
|
||||
return 'Maintenance';
|
||||
case 'offline':
|
||||
return 'Hors ligne';
|
||||
case 'error':
|
||||
return 'Erreur';
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
factory Machine.fromJson(Map<String, dynamic> json) {
|
||||
return Machine(
|
||||
uuid: json['uuid'] as String,
|
||||
name: json['name'] as String,
|
||||
type: json['type'] as String,
|
||||
status: json['status'] as String,
|
||||
qrCode: json['qr_code'] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user