Files
Core_Be/Models/CustomerSubscription.cs
Dhananjaya99 bffc9b1686 first commit
2026-09-28 11:44:26 +05:30

62 lines
3.1 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Fitness_core_BE.Models
{
public class CustomerSubscription
{
[Key]
public Guid SubscriptionId { get; set; }
public Guid FKCustomerPlanId { get; set; }
[ForeignKey("FKCustomerPlanId")]
public virtual CustomerPlan CustomerPlan { get; set; }
// Tenant-bucket entity: this FK holds a TenantCustomerLinkId (not the central
// Customer.CusId directly) -- see Models/TenantCustomerLink.cs.
public Guid FKCustomerId { get; set; }
[ForeignKey("FKCustomerId")]
public virtual TenantCustomerLink TenantCustomerLink { get; set; }
public DateTime OnboardDate { get; set; } = DateTime.UtcNow;
// Set once, at creation, and never touched again -- see RenewalDate for the field that
// actually reflects the subscription's current cycle end / renewal-eligibility date.
public DateTime? ExpiryDate { get; set; }
// Advances on every approved renewal cycle; every "is this due/expiring/current" query,
// filter, sort or status display should read this instead of ExpiryDate.
public DateTime? RenewalDate { get; set; }
public bool IsActive { get; set; } = true;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
// Set together at assignment time; "was a discount given" is DiscountValue.HasValue.
public string? DiscountType { get; set; } // "Percentage" | "Flat"
public decimal? DiscountValue { get; set; }
/// <summary>Member has consented to auto-deduct renewals from FKAutoChargeCardId.</summary>
public bool AutoChargeEnabled { get; set; } = false;
public Guid? FKAutoChargeCardId { get; set; }
[ForeignKey("FKAutoChargeCardId")]
public virtual CustomerCards? AutoChargeCard { get; set; }
// Session-count tracking for CustomerPlan.SessionsPerCycle plans (null for unlimited
// gym-access plans). SessionsUsedThisCycle resets on renewal; SessionsCarriedOver holds
// unused sessions brought forward when CustomerPlan.SessionRolloverPolicy == "GracePeriod"
// and is cleared once RolloverGraceDays elapses. Booking creation increments
// SessionsUsedThisCycle instead of duplicating this counter per facility.
public int SessionsUsedThisCycle { get; set; } = 0;
public int SessionsCarriedOver { get; set; } = 0;
// Set at renewal approval time when CustomerPlan.SessionRolloverPolicy == "GracePeriod"
// (now + RolloverGraceDays); null when there's nothing carried over. Booking creation
// treats SessionsCarriedOver as spent/expired once this passes, even though the column
// itself isn't zeroed until the next renewal -- see BookingService.CreateMemberBooking.
public DateTime? SessionsCarriedOverExpiresAt { get; set; }
public virtual ICollection<SubscriptionMember> SubscriptionMembers { get; set; }
public virtual ICollection<SubscriptionInstallment> SubscriptionInstallments { get; set; }
}
}