using CommunityToolkit.Mvvm.ComponentModel; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Text.Json.Serialization; using System.Threading.Tasks; namespace gehGassiApp.Domain.Common { /// /// Repräsentiert eine Adresse /// public class Address : ObservableObject { private string _addressLine1; private string _addressLine2; private string _city; private string _zip; private string _state; private string _countryCode; /// /// Optionale Adresszeile 1 /// [MaxLength(100)] [JsonPropertyName("addressLine1")] public string AddressLine1 { get => _addressLine1; set { _addressLine1 = value; OnPropertyChanged(AddressLine1); OnPropertyChanged(nameof(Preview)); } } /// /// Optionale Adresszeile 2 /// [MaxLength(100)] [JsonPropertyName("addressLine2")] public string AddressLine2 { get => _addressLine2; set { _addressLine2 = value; OnPropertyChanged(AddressLine2); OnPropertyChanged(nameof(Preview)); } } /// /// Optional: Stadt / Ort /// [MaxLength(100)] [JsonPropertyName("city")] public string City { get => _city; set { _city = value; OnPropertyChanged(City); OnPropertyChanged(nameof(Preview)); } } /// /// Optinale PLZ /// [MaxLength(20)] [JsonPropertyName("zip")] public string Zip { get => _zip; set { _zip = value; OnPropertyChanged(nameof(Zip)); OnPropertyChanged(nameof(Preview)); } } /// /// Bundesland / Staat /// [MaxLength(100)] [JsonPropertyName("state")] public string State { get => _state; set { _state = value; OnPropertyChanged(nameof(State)); OnPropertyChanged(nameof(Preview)); } } /// /// ISO2 Ländercode /// [Required] [MaxLength(2)] [JsonPropertyName("countryCode")] public string CountryCode { get => _countryCode; set { _countryCode = value; OnPropertyChanged(nameof(CountryCode)); OnPropertyChanged(nameof(Preview)); } } /// /// Anzeige der Adresse als ein String /// [NotMapped] [JsonIgnore] public string Preview { get { var line = string.Empty; if (!string.IsNullOrWhiteSpace(AddressLine1)) { line += $"{AddressLine1}"; } if (!string.IsNullOrWhiteSpace(AddressLine2)) { if (!string.IsNullOrWhiteSpace(line)) line += ", "; line += $"{AddressLine2}"; } if (!string.IsNullOrWhiteSpace(Zip)) { if (!string.IsNullOrWhiteSpace(line)) line += ", "; line += $"{Zip}"; } if (!string.IsNullOrWhiteSpace(City)) { if (!string.IsNullOrWhiteSpace(line)) line += ", "; line += $"{City}"; } return line; } } /// /// Anzeige Ort mit Komma für die Detailansicht. /// Wenn ort, dann Ort, sonst leer /// [NotMapped] [JsonIgnore] public string CityWithComma { get { if(!string.IsNullOrWhiteSpace(City)) return $"{City}, "; return string.Empty; } } /// /// Klonen der Adresse /// /// Addresse public Address Clone() { var clonedAddress = new Address() { AddressLine1 = AddressLine1, AddressLine2 = AddressLine2, Zip = Zip, City = City, State = State, CountryCode = CountryCode }; return clonedAddress; } } }