using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace Lagerbestand.Models; /// /// Represents a customer who stores tires at the shop. /// A customer can have multiple vehicles. /// public class Customer { [Key] public Guid Id { get; set; } = Guid.NewGuid(); [MaxLength(100)] public string? FirstName { get; set; } [Required] [MaxLength(100)] public string LastName { get; set; } = string.Empty; [MaxLength(200)] public string? Company { get; set; } [MaxLength(20)] public string? Phone { get; set; } [MaxLength(100)] public string? Email { get; set; } [MaxLength(500)] public string? Notes { get; set; } /// /// Customer number for easy identification (e.g., K-0001) /// [MaxLength(20)] public string CustomerNumber { get; set; } = string.Empty; public bool IsActive { get; set; } = true; public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime? UpdatedAt { get; set; } /// /// Navigation property for customer's vehicles /// public ICollection Vehicles { get; set; } = new List(); /// /// Navigation property for customer's stored tire stacks /// public ICollection TireStacks { get; set; } = new List(); /// /// Full name of the customer /// [NotMapped] public string FullName => $"{FirstName} {LastName}".Trim(); /// /// Display name including company if available /// [NotMapped] public string DisplayName => string.IsNullOrEmpty(Company) ? FullName : $"{FullName} ({Company})"; /// /// Gets the primary vehicle or the first vehicle if no primary is set /// [NotMapped] public Vehicle? PrimaryVehicle => Vehicles .Where(v => v.IsActive) .OrderByDescending(v => v.IsPrimary) .ThenBy(v => v.CreatedAt) .FirstOrDefault(); /// /// Gets all active vehicles for this customer /// [NotMapped] public IEnumerable ActiveVehicles => Vehicles.Where(v => v.IsActive); }