|
| 1 | +using System.ComponentModel.DataAnnotations; |
| 2 | +using System.ComponentModel.DataAnnotations.Schema; |
| 3 | +using Aquiis.Core.Validation; |
| 4 | + |
| 5 | +namespace Aquiis.Core.Entities; |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// Represents work performed on a property WITHOUT workflow/status tracking. |
| 9 | +/// Repairs capture what work was done (or is being done) without the complexity |
| 10 | +/// of MaintenanceRequest workflow (no Status, Priority, or Assignment). |
| 11 | +/// Use CompletedOn to determine if work is finished (null = in progress, date = completed). |
| 12 | +/// </summary> |
| 13 | +public class Repair : BaseModel |
| 14 | +{ |
| 15 | + // Core Identity |
| 16 | + [RequiredGuid] |
| 17 | + [Display(Name = "Organization ID")] |
| 18 | + public Guid OrganizationId { get; set; } = Guid.Empty; |
| 19 | + |
| 20 | + [RequiredGuid] |
| 21 | + public Guid PropertyId { get; set; } |
| 22 | + |
| 23 | + // Optional Relationships (Soft References) |
| 24 | + /// <summary> |
| 25 | + /// Optional: Links this repair to a MaintenanceRequest workflow (Professional product). |
| 26 | + /// Null for standalone repairs (SimpleStart product). |
| 27 | + /// </summary> |
| 28 | + public Guid? MaintenanceRequestId { get; set; } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Optional: Links this repair to a specific lease/tenant. |
| 32 | + /// </summary> |
| 33 | + public Guid? LeaseId { get; set; } |
| 34 | + |
| 35 | + // Repair Details |
| 36 | + [Required] |
| 37 | + [StringLength(200)] |
| 38 | + [Display(Name = "Description")] |
| 39 | + public string Description { get; set; } = string.Empty; |
| 40 | + |
| 41 | + [StringLength(50)] |
| 42 | + [Display(Name = "Repair Type")] |
| 43 | + public string RepairType { get; set; } = string.Empty; // From ApplicationConstants.RepairTypes |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Optional: Date when work was actually completed. |
| 47 | + /// Null = work in progress or not yet completed. |
| 48 | + /// Date = work finished on this date. |
| 49 | + /// Since Repairs have no Status field, CompletedOn provides definitive completion date. |
| 50 | + /// </summary> |
| 51 | + [Display(Name = "Completed On")] |
| 52 | + public DateTime? CompletedOn { get; set; } |
| 53 | + |
| 54 | + // Cost & Duration |
| 55 | + [Column(TypeName = "decimal(18,2)")] |
| 56 | + [Display(Name = "Cost")] |
| 57 | + public decimal Cost { get; set; } |
| 58 | + |
| 59 | + [Display(Name = "Duration (Minutes)")] |
| 60 | + public int DurationMinutes { get; set; } // Time spent on repair |
| 61 | + |
| 62 | + // Who did the work |
| 63 | + [StringLength(100)] |
| 64 | + [Display(Name = "Contractor/Company Name")] |
| 65 | + public string ContractorName { get; set; } = string.Empty; // Company or person name (e.g., "ABC Plumbing & Heating" or "John Doe") |
| 66 | + |
| 67 | + [StringLength(100)] |
| 68 | + [Display(Name = "Contact Person")] |
| 69 | + public string ContactPerson { get; set; } = string.Empty; // Specific person at company (optional for companies) |
| 70 | + |
| 71 | + [StringLength(20)] |
| 72 | + [Display(Name = "Contractor Phone")] |
| 73 | + public string ContractorPhone { get; set; } = string.Empty; // Optional: "555-1234" |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// Optional: Link to Contractor entity when contractor list is implemented. |
| 77 | + /// When null, contractor details are stored in text fields (ContractorName/ContactPerson/ContractorPhone). |
| 78 | + /// </summary> |
| 79 | + [Display(Name = "Contractor ID")] |
| 80 | + public Guid? ContractorId { get; set; } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Future: Link to formal Contact entity when added to the system. |
| 84 | + /// </summary> |
| 85 | + public Guid? ContactId { get; set; } |
| 86 | + |
| 87 | + // Additional Details |
| 88 | + [StringLength(2000)] |
| 89 | + [Display(Name = "Notes")] |
| 90 | + public string Notes { get; set; } = string.Empty; |
| 91 | + |
| 92 | + [StringLength(500)] |
| 93 | + [Display(Name = "Parts Replaced")] |
| 94 | + public string PartsReplaced { get; set; } = string.Empty; // e.g., "Faucet cartridge, shower seal" |
| 95 | + |
| 96 | + [Display(Name = "Warranty Applies")] |
| 97 | + public bool WarrantyApplies { get; set; } = false; |
| 98 | + |
| 99 | + [Display(Name = "Warranty Expires On")] |
| 100 | + public DateTime? WarrantyExpiresOn { get; set; } |
| 101 | + |
| 102 | + // Navigation Properties |
| 103 | + public virtual Property? Property { get; set; } |
| 104 | + public virtual MaintenanceRequest? MaintenanceRequest { get; set; } |
| 105 | + public virtual Lease? Lease { get; set; } |
| 106 | + |
| 107 | + // Computed Properties |
| 108 | + [NotMapped] |
| 109 | + [Display(Name = "Duration")] |
| 110 | + public string DurationDisplay |
| 111 | + { |
| 112 | + get |
| 113 | + { |
| 114 | + if (DurationMinutes < 60) |
| 115 | + return $"{DurationMinutes} minutes"; |
| 116 | + |
| 117 | + var hours = DurationMinutes / 60; |
| 118 | + var minutes = DurationMinutes % 60; |
| 119 | + return minutes > 0 |
| 120 | + ? $"{hours}h {minutes}m" |
| 121 | + : $"{hours} hour{(hours > 1 ? "s" : "")}"; |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + [NotMapped] |
| 126 | + [Display(Name = "Under Warranty")] |
| 127 | + public bool IsUnderWarranty => WarrantyApplies && |
| 128 | + WarrantyExpiresOn.HasValue && |
| 129 | + WarrantyExpiresOn.Value > DateTime.Today; |
| 130 | + |
| 131 | + [NotMapped] |
| 132 | + [Display(Name = "Completed")] |
| 133 | + public bool IsCompleted => CompletedOn.HasValue; //Provides quick check for completion status. If no value, work is In Progess in the display. |
| 134 | +} |
0 commit comments