using AutobusApi.Domain.Common; using AutobusApi.Domain.Enums; namespace AutobusApi.Domain.Entities; public class TicketGroup : EntityBase { public string BuyerFirstName { get; set; } = null!; public string BuyerLastName { get; set; } = null!; public string BuyerPhoneNumber { get; set; } = null!; public string BuyerEmailAddress { get; set; } = null!; public string PassengerFirstName { get; set; } = null!; public string PassengerLastName { get; set; } = null!; public string PassengerPatronymic { get; set; } = null!; public Sex PassengerSex { get; set; } public DateOnly PassengerBirthDate { get; set; } public DateTime PurchaseDateTimeUtc { get; set; } public bool IsReturned { get; set; } public int? UserId { get; set; } public User? User { get; set; } public int TicketDocumentId { get; set; } public TicketDocument TicketDocument { get; set; } = null!; public ICollection Tickets { get; set; } = new List(); public DateTime GetDepartureDateTimeUtc() { var firstTicket = Tickets.OrderBy(t => t.VehicleEnrollment.GetDepartureDateTimeUtc(t.DepartureAddressId)).First(); return firstTicket.VehicleEnrollment.GetDepartureDateTimeUtc(firstTicket.DepartureAddressId); } public DateTime GetArrivalDateTimeUtc() { var lastTicket = Tickets.OrderBy(t => t.VehicleEnrollment.GetDepartureDateTimeUtc(t.DepartureAddressId)).Last(); return lastTicket.VehicleEnrollment.GetArrivalDateTimeUtc(lastTicket.ArrivalAddressId); } public TimeSpan GetTravelTime() { return GetArrivalDateTimeUtc() - GetDepartureDateTimeUtc(); } public double GetCost() { return Tickets.Aggregate(0.0, (sum, ticket) => sum + ticket.VehicleEnrollment.GetCost(ticket.DepartureAddressId, ticket.ArrivalAddressId)); } }