Files
Core_Be/Interfaces/ICustomerSubscriptionRepository.cs
T
HarithaRandunu 5d711bd13e Facility booking-mode redesign, multi-plan subscriptions, and Classes
Implements the facility-classes-booking-dashboard plan (backend):

- Facility.BookingMode (single Scheduled/AdHoc choice) replaced with
  independent SupportsClasses/SupportsBooking flags, so one facility
  can run a class and accept walk-in bookings; a running class now
  blocks walk-in booking for its window on both create and reschedule.
- CustomerPlan.GrantsGymAccess + CustomerPlanClass join table let a
  customer hold one gym-access plan plus any number of class-only
  plans. Replaced the old single-subscription resolution
  (GetActiveSubscriptionByCustomerId/HasAnyActiveSubscriptionAsync)
  with gym-access-aware and class-aware resolvers across booking
  creation/cancellation, plan assignment, and customer self-service.
  Fixed ChangeMembershipPlan/renewal plan-changes, which resolved "the
  subscription to replace" by most-recent-created and would have
  deactivated a member's class subscription instead of their gym one.
- New FacilityClass model: recurring class definitions (Daily/Weekly/
  Monthly/Custom) with lazy occurrence generation (8-week horizon,
  race-safe via a unique index) and proper unlimited-capacity handling.
  "Mark not held" replaces the old bare-cancel: cascades to cancel and
  refund every confirmed booking on the occurrence through the same
  core CancelBooking uses, and frees the slot for walk-in booking.
  Scheduling conflicts (a walk-in booking now overlapping a class) are
  surfaced for staff to resolve via the existing Reschedule flow.
- Renamed the pre-existing "AdHoc" booking-mode terminology to
  "WalkIn" throughout (routes, methods, DTOs, the stored BookingMode
  value) for a clearer, simpler name.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-09 14:26:59 +05:30

71 lines
4.6 KiB
C#

using Fitness_core_BE.Models;
namespace Fitness_core_BE.Interfaces
{
public interface ICustomerSubscriptionRepository
{
Task AddCustomerSubscriptionAsync(
CustomerSubscription subscription,
CustomerSubItem initialSubItem,
SubscriptionMember primaryMember,
IReadOnlyCollection<SubscriptionInstallment> installments,
CancellationToken ct = default);
Task<CustomerPlan?> GetPlanByIdAsync(Guid customerPlanId, CancellationToken ct = default);
Task<bool> IsActiveCustomerAsync(Guid customerId, CancellationToken ct = default);
Task<List<CustomerSubItem>> GetSubItemsAsync(
Guid subscriptionId,
bool activeOnly,
bool newestFirst,
CancellationToken ct = default);
Task AddSubItemAsync(CustomerSubItem subItem, CancellationToken ct = default);
Task<CustomerInvoice?> GetLatestInvoiceAsync(Guid subscriptionId, CancellationToken ct = default);
Task<decimal> GetApprovedPaymentTotalAsync(Guid invoiceId, CancellationToken ct = default);
Task<CustomerCards?> GetCardByIdAsync(Guid cardId, CancellationToken ct = default);
Task<CustomerSubscription?> GetCustomerSubscriptionById(Guid subscriptionId);
Task<List<CustomerSubscription>> GetCustomerSubscriptionsByCustomerId(Guid customerId);
/// <summary>True for an ordinary plan (no CustomerPlanClass links) or a class-linked
/// plan with GrantsGymAccess == true.</summary>
Task<bool> PlanGrantsGymAccessAsync(Guid customerPlanId, CancellationToken ct = default);
/// <summary>The customer's active subscription whose plan grants gym access, if any --
/// at most one can exist (enforced by HasActiveGymAccessPlanAsync at assignment time).
/// Primary-only, same as the old GetActiveSubscriptionByCustomerId this replaces.</summary>
Task<CustomerSubscription?> GetActiveGymAccessSubscriptionAsync(Guid customerId);
/// <summary>The customer's active subscription on this exact plan, if any -- the
/// idempotency check for re-assigning a class-only plan (which, unlike a gym plan,
/// doesn't block on ANY other active plan, only a duplicate of itself).</summary>
Task<CustomerSubscription?> GetActiveSubscriptionForPlanAsync(Guid customerId, Guid customerPlanId);
/// <summary>The subscription that covers booking a specific class, preferring one with
/// quota left this cycle. Null if none of the customer's active subscriptions link to
/// this class at all.</summary>
Task<CustomerSubscription?> GetActiveSubscriptionForClassAsync(Guid customerId, Guid facilityClassId);
// Whether this customer is currently an active member (primary OR secondary/group) of
// ANY gym-access subscription at this gym -- a class-only subscription never counts, so
// unlimited concurrent class-only subscriptions are allowed. "One customer, one
// GYM-ACCESS plan at a time" is enforced everywhere a gym plan gets assigned, not just
// the primary path.
Task<bool> HasActiveGymAccessPlanAsync(Guid customerId, CancellationToken ct = default);
Task<SubscriptionMember> AddSubscriptionMemberAsync(SubscriptionMember member);
Task<int> GetActiveMemberCountAsync(Guid subscriptionId);
Task<SubscriptionMember?> GetSubscriptionMemberAsync(Guid subscriptionMemberId);
Task<SubscriptionMember?> GetActiveSubscriptionMemberByCustomerAsync(Guid subscriptionId, Guid customerId);
Task<List<CustomerSubscription>> GetSubscriptionsForCustomerAsync(Guid customerId);
Task<List<SubscriptionInstallment>> GetInstallmentsAsync(Guid subscriptionId);
// Renewal-approval workflow (SubscriptionRenewalApprovalService.ApproveAsync): advances
// RenewalDate only -- ExpiryDate is never touched again after creation.
Task AdvanceRenewalDateAsync(Guid subscriptionId, DateTime newRenewalDate, CancellationToken ct = default);
// Removes the subscription's current-cycle installment rows before a fresh schedule is
// added for the newly-approved cycle. Hard delete, not soft-deactivate: a unique index on
// (FKSubscriptionId, InstallmentNo) means a soft-deactivated row would still collide with
// the new cycle's schedule restarting at InstallmentNo 1 on the same subscription.
Task DeactivatePriorInstallmentsAsync(Guid subscriptionId, CancellationToken ct = default);
Task AddInstallmentsAsync(IReadOnlyCollection<SubscriptionInstallment> installments, CancellationToken ct = default);
}
}