using PowderCoating.Core.Enums;
namespace PowderCoating.Core.Entities;
public class GiftCertificate : BaseEntity
{
/// Certificate code shown on the physical/emailed certificate. Format: GC-YYMM-####
public string CertificateCode { get; set; } = string.Empty;
public decimal OriginalAmount { get; set; }
public decimal RedeemedAmount { get; set; }
public decimal RemainingBalance => OriginalAmount - RedeemedAmount;
// Who it's for (optional — may be given to an unknown recipient)
public int? RecipientCustomerId { get; set; }
public string? RecipientName { get; set; } // Free-text name for non-customers
public string? RecipientEmail { get; set; }
// How it was issued
public GiftCertificateIssuedReason IssuedReason { get; set; } = GiftCertificateIssuedReason.Sold;
// If sold: what the buyer paid (may be less than face value for a promotional sale)
public decimal? PurchasePrice { get; set; }
public int? PurchasingCustomerId { get; set; }
public GiftCertificateStatus Status { get; set; } = GiftCertificateStatus.Active;
public DateTime IssueDate { get; set; } = DateTime.UtcNow;
public DateTime? ExpiryDate { get; set; }
public string? Notes { get; set; }
public string? IssuedById { get; set; }
/// Set when this GC was sold via an invoice line item.
public int? SourceInvoiceItemId { get; set; }
/// Groups all certificates created in a single bulk run. Null for individually issued certs.
public Guid? BatchId { get; set; }
// Navigation
public virtual Customer? RecipientCustomer { get; set; }
public virtual Customer? PurchasingCustomer { get; set; }
public virtual ApplicationUser? IssuedBy { get; set; }
public virtual ICollection Redemptions { get; set; } = new List();
}
public class GiftCertificateRedemption : BaseEntity
{
public int GiftCertificateId { get; set; }
public int InvoiceId { get; set; }
public decimal AmountRedeemed { get; set; }
public DateTime RedeemedDate { get; set; } = DateTime.UtcNow;
public string? RedeemedById { get; set; }
// Navigation
public virtual GiftCertificate GiftCertificate { get; set; } = null!;
public virtual Invoice Invoice { get; set; } = null!;
public virtual ApplicationUser? RedeemedBy { get; set; }
}