/// Postanschrift — Value-Object, identitätslos. /// /// Tritt im Domain an drei Stellen auf: am `Customer` (Stamm-Adresse) und /// als `deliveryAddressSnapshot` auf der `Delivery` (eingefrorene Kopie der /// Adresse zum Zeitpunkt der Belegerzeugung, damit nachträgliche Änderungen /// am Stammdatensatz die ausgelieferte Tour nicht „verschieben"). Spiegelt /// das Backend-DTO `Address` 1:1. class Address { const Address({ required this.street, required this.houseNumber, required this.postalCode, required this.city, required this.country, this.addition, }); final String street; final String houseNumber; final String postalCode; final String city; /// Land laut ERP-Länderstamm (z. B. „Deutschland"), leer wenn unbekannt. final String country; /// Freier Adresszusatz aus dem ERP — praktisch Ortsteil, Etage oder /// Hinweis („Holzheim", „3 Etage", „Parterre"). `null`, wenn leer. final String? addition; static const Set _germany = { 'd', 'de', 'deu', 'deutschland', 'germany', 'brd', }; /// Land für die Anzeige — nur außerhalb Deutschlands, sonst `null`. String? get foreignCountry { final c = country.trim(); if (c.isEmpty || _germany.contains(c.toLowerCase())) return null; return c; } /// Einzeilige Anschrift „Straße Nr, PLZ Ort" (+ Land, falls Ausland). /// Ohne Zusatz — so auch als Such-Query für Maps geeignet. String get oneLine => [ '$street $houseNumber, $postalCode $city', if (foreignCountry case final c?) c, ].join(', '); /// Wie [oneLine], mit Adresszusatz in Klammern — für Listen, damit der /// Fahrer Ortsteil/Etage auf einen Blick sieht. String get oneLineWithAddition { final a = addition?.trim(); return a == null || a.isEmpty ? oneLine : '$oneLine ($a)'; } Address copyWith({ String? street, String? houseNumber, String? postalCode, String? city, String? country, String? addition, }) { return Address( street: street ?? this.street, houseNumber: houseNumber ?? this.houseNumber, postalCode: postalCode ?? this.postalCode, city: city ?? this.city, country: country ?? this.country, addition: addition ?? this.addition, ); } @override bool operator ==(Object other) => identical(this, other) || other is Address && other.street == street && other.houseNumber == houseNumber && other.postalCode == postalCode && other.city == city && other.country == country && other.addition == addition; @override int get hashCode => Object.hash(street, houseNumber, postalCode, city, country, addition); }