import { S } from "./schedule-10ca7moa.js";
import { B } from "./booking-FmPZohXk.js";
import { E } from "./eventTypeRepository-okiT_hD6.js";
import { R } from "./formResponse-4j2gt5Il.js";
import { T } from "./team-9uajEZ51.js";
import { U } from "./user-YNqbx2fx.js";
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 }
      }
    });
  }
}
export {
  B as PrismaBookingRepository,
  E as PrismaEventTypeRepository,
  PrismaOOORepository,
  R as PrismaRoutingFormResponseRepository,
  S as PrismaScheduleRepository,
  PrismaSelectedSlotRepository,
  T as PrismaTeamRepository,
  U as PrismaUserRepository
};
