Files
Core_Be/Interfaces/IFacilityClassRepository.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

43 lines
2.4 KiB
C#

using Fitness_core_BE.Models;
namespace Fitness_core_BE.Interfaces
{
public interface IFacilityClassRepository
{
Task<FacilityClass> CreateFacilityClass(FacilityClass facilityClass);
Task<List<FacilityClass>> GetFacilityClasses(Guid clientId, bool includeInactive = false);
Task<FacilityClass?> GetFacilityClassById(Guid facilityClassId);
Task<FacilityClass> UpdateFacilityClass(FacilityClass facilityClass);
/// <summary>Active, non-Custom classes whose OccurrencesGeneratedThrough hasn't reached
/// the horizon yet -- Custom classes are never generated, their occurrences are always
/// written explicitly.</summary>
Task<List<FacilityClass>> GetClassesNeedingGenerationAsync(Guid clientId, DateTime horizon);
/// <summary>Existing occurrence start times for this class in [from, to) -- for
/// pre-generation dedup. The unique (FKFacilityClassId, StartTime) index is the actual
/// race-safety net; this just avoids the common sequential case needlessly retrying.</summary>
Task<HashSet<DateTime>> GetExistingOccurrenceStartTimesAsync(Guid facilityClassId, DateTime from, DateTime to);
Task AddOccurrencesAsync(IEnumerable<FacilitySession> occurrences);
Task<List<FacilitySession>> GetOccurrencesForClassAsync(Guid facilityClassId, bool includeCancelled);
/// <summary>Deletes occurrences that are both in the future and have zero Booking rows
/// of ANY status (a Cancelled booking still holds the FK, so it would fail the delete) --
/// the safe-to-regenerate set when a class's recurrence rule changes. Returns the count
/// deleted.</summary>
Task<int> DeleteFutureUnbookedOccurrencesAsync(Guid facilityClassId, DateTime nowUtc);
/// <summary>Confirmed, non-cancelled ad-hoc bookings whose window overlaps an active
/// (non-cancelled) class occurrence on the same facility -- surfaced to staff as a
/// conflict to resolve via the existing Reschedule flow, not auto-resolved.</summary>
Task<List<Booking>> GetSchedulingConflictsAsync(Guid clientId);
/// <summary>Links a newly-created CustomerPlan to the class it's sold against -- the
/// "Manage Plan" action's whole reason for being a class-scoped entry point rather than
/// the general Plans tab.</summary>
Task LinkPlanToClassAsync(Guid customerPlanId, Guid facilityClassId);
}
}