using Baya.Domain.Common;
using Baya.Domain.Entities.Geography;

namespace Baya.Domain.Entities.Identity;

/// <summary>
/// A customer's saved service location. The street address and recipient contact are encrypted PII at
/// rest (decrypted only in the owner's own read path); <see cref="Latitude"/>/<see cref="Longitude"/> are
/// produced by the <c>IGeocoder</c> seam and later consumed by the EVV distance check (b9). Exactly one
/// address per customer is primary — enforced in the handler and by a filtered unique index.
/// </summary>
public class CustomerAddress : BaseEntity<long>
{
    public long CustomerId { get; set; }
    public CustomerProfile Customer { get; set; }

    public long CityId { get; set; }
    public City City { get; set; }

    public long? DistrictId { get; set; }
    public District District { get; set; }

    /// <summary>A label ("خانه"/"محل کار") — not PII, stored plaintext.</summary>
    public string Title { get; set; }

    /// <summary>Encrypted at rest.</summary>
    public string AddressLine { get; set; }

    /// <summary>Encrypted at rest.</summary>
    public string PostalCode { get; set; }

    public decimal? Latitude { get; set; }
    public decimal? Longitude { get; set; }

    /// <summary>How the stored coordinate was obtained: <see cref="GeocodeSources.UserPin"/> when the
    /// customer dropped a pin (their exact door, preferred for the EVV distance check) or
    /// <see cref="GeocodeSources.Geocoder"/> when the server geocoded the street address.</summary>
    public string GeocodeSource { get; set; }

    public bool IsPrimary { get; set; }

    /// <summary>Encrypted at rest.</summary>
    public string RecipientName { get; set; }

    /// <summary>Encrypted at rest.</summary>
    public string RecipientPhone { get; set; }

    public DateTimeOffset? DeletedAt { get; set; }
}
