"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const schedule = require("./schedule-_LLzTgqB.cjs");
const booking = require("./booking-BJpI8rUs.cjs");
const eventTypeRepository = require("./eventTypeRepository-sBa8-vDB.cjs");
const formResponse = require("./formResponse-1uX8yEhp.cjs");
const team = require("./team-hx-1vV9e.cjs");
const user = require("./user-A6mRFMt_.cjs");
class PrismaOOORepository {
  constructor(prismaClient) {
    this.prismaClient = prismaClient;
  }
  async findManyOOO({
    startTimeDate,
    endTimeDate,
    allUserIds
  }) {
    return this.prismaClient.outOfOfficeEntry.findMany({
      where: {
        userId: {
          in: allUserIds
        },
        OR: [
          // outside of range
          // (start <= 'dateTo' AND end >= 'dateFrom')
          {
            start: {
              lte: endTimeDate
            },
            end: {
              gte: startTimeDate
            }
          },
          // start is between dateFrom and dateTo but end is outside of range
          // (start <= 'dateTo' AND end >= 'dateTo')
          {
            start: {
              lte: endTimeDate
            },
            end: {
              gte: endTimeDate
            }
          },
          // end is between dateFrom and dateTo but start is outside of range
          // (start <= 'dateFrom' OR end <= 'dateTo')
          {
            start: {
              lte: startTimeDate
            },
            end: {
              lte: endTimeDate
            }
          }
        ]
      },
      select: {
        id: true,
        start: true,
        end: true,
        user: {
          select: {
            id: true,
            name: true
          }
        },
        toUser: {
          select: {
            id: true,
            username: true,
            name: true
          }
        },
        reason: {
          select: {
            id: true,
            emoji: true,
            reason: true
          }
        }
      }
    });
  }
}
class PrismaSelectedSlotRepository {
  constructor(prismaClient) {
    this.prismaClient = prismaClient;
  }
  async findFirst({ where }) {
    return await this.prismaClient.selectedSlots.findFirst({
      where
    });
  }
  async findReservedByOthers({
    slot,
    eventTypeId,
    uid
  }) {
    return await this.findFirst({
      where: {
        slotUtcStartDate: slot.utcStartIso,
        slotUtcEndDate: slot.utcEndIso,
        eventTypeId,
        uid: { not: uid },
        releaseAt: { gt: /* @__PURE__ */ new Date() }
      }
    });
  }
  async findManyReservedByOthers(slots, eventTypeId, uid) {
    return await this.prismaClient.selectedSlots.findMany({
      where: {
        OR: slots.map((slot) => ({
          slotUtcStartDate: slot.utcStartIso,
          slotUtcEndDate: slot.utcEndIso,
          eventTypeId,
          uid: { not: uid },
          releaseAt: { gt: /* @__PURE__ */ new Date() }
        }))
      },
      select: {
        slotUtcStartDate: true,
        slotUtcEndDate: true
      }
    });
  }
  async findManyUnexpiredSlots({
    userIds,
    currentTimeInUtc
  }) {
    return this.prismaClient.selectedSlots.findMany({
      where: {
        userId: { in: userIds },
        releaseAt: { gt: currentTimeInUtc }
      },
      select: {
        id: true,
        slotUtcStartDate: true,
        slotUtcEndDate: true,
        userId: true,
        isSeat: true,
        eventTypeId: true,
        uid: true
      }
    });
  }
  async deleteManyExpiredSlots({
    eventTypeId,
    currentTimeInUtc
  }) {
    return this.prismaClient.selectedSlots.deleteMany({
      where: {
        eventTypeId: { equals: eventTypeId },
        releaseAt: { lt: currentTimeInUtc }
      }
    });
  }
}
exports.PrismaScheduleRepository = schedule.ScheduleRepository;
exports.PrismaBookingRepository = booking.BookingRepository;
exports.PrismaEventTypeRepository = eventTypeRepository.EventTypeRepository;
exports.PrismaRoutingFormResponseRepository = formResponse.RoutingFormResponseRepository;
exports.PrismaTeamRepository = team.TeamRepository;
exports.PrismaUserRepository = user.UserRepository;
exports.PrismaOOORepository = PrismaOOORepository;
exports.PrismaSelectedSlotRepository = PrismaSelectedSlotRepository;
