toDomain static method
Implementation
static Order toDomain(OrderFirestoreDTO dto) {
final order = Order(
orderId: dto.id,
customerId: dto.customerId,
items: dto.items
.map(
(itemDto) => OrderItem(
productId: itemDto.productId,
quantity: itemDto.quantity.toDouble(),
unitPrice: Money.inrPaise(
itemDto.unitPrice,
), // Assuming INR default
// Mapping enums safely, defaulting if needed or throwing
productType: ProductType.values.firstWhere(
(e) => e.name == itemDto.type,
),
unit: ProductUnit.values.firstWhere(
(e) => e.name == itemDto.unit,
),
),
)
.toList(),
timeSlot: TimeSlot(
startHour: dto.timeSlot['startHour']!,
endHour: dto.timeSlot['endHour']!,
startMinute: dto.timeSlot['startMinute'] ?? 0,
endMinute: dto.timeSlot['endMinute'] ?? 0,
),
createdAt: dto.placedAt,
);
// Replay state
final targetStatus = OrderStatus.values.firstWhere(
(e) => e.name == dto.status,
);
_hydrateStatus(order, targetStatus);
return order;
}