using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace PSTW_CentralSystem.Areas.Bookings.Models { public enum BookingStatus { Pending = 0, Approved = 1, Rejected = 2, Cancelled = 3 } [Table("bookings")] public class Booking : IValidatableObject { [Key] [Column("BookingId")] public int BookingId { get; set; } /// FK → aspnetusers(Id) (int) [Required] public int RequestedByUserId { get; set; } /// If booking on behalf of someone else; else null. public int? TargetUserId { get; set; } /// Snapshot of org at submission time. public int? DepartmentId { get; set; } // FK → departments(DepartmentId) public int? CompanyId { get; set; } // FK → companies(CompanyId) /// Room being booked. [Required] public int RoomId { get; set; } // FK → rooms(RoomId) [Required, StringLength(150)] public string Title { get; set; } = string.Empty; [StringLength(300)] public string? Purpose { get; set; } /// Use UTC to avoid TZ headaches; map to DATETIME in MySQL. [Required] public DateTime StartUtc { get; set; } [Required] public DateTime EndUtc { get; set; } [StringLength(500)] public string? Note { get; set; } [Required] public DateTime CreatedUtc { get; set; } = DateTime.UtcNow; [Required] public DateTime LastUpdatedUtc { get; set; } = DateTime.UtcNow; [Required] public BookingStatus CurrentStatus { get; set; } = BookingStatus.Pending; // ---- validation ---- public IEnumerable Validate(ValidationContext _) { if (EndUtc <= StartUtc) yield return new ValidationResult("End time must be after start time.", new[] { nameof(EndUtc) }); if ((EndUtc - StartUtc).TotalMinutes < 10) yield return new ValidationResult("Minimum booking duration is 10 minutes.", new[] { nameof(StartUtc), nameof(EndUtc) }); } } [Table("rooms")] public class Room { [Key] public int RoomId { get; set; } [Required, StringLength(120)] public string RoomName { get; set; } = string.Empty; [StringLength(40)] public string? LocationCode { get; set; } public int? Capacity { get; set; } public bool IsActive { get; set; } = true; } }