import { captureException } from "@sentry/nextjs";
import { C as WatchlistSeverity, D as WatchlistType, p as prisma } from "./user--mpkKOwW.js";
class WatchlistRepository {
  async getBlockedEmailInWatchlist(email) {
    const [, domain] = email.split("@");
    try {
      const emailInWatchlist = await prisma.watchlist.findFirst({
        where: {
          severity: WatchlistSeverity.CRITICAL,
          OR: [
            { type: WatchlistType.EMAIL, value: email },
            { type: WatchlistType.DOMAIN, value: domain }
          ]
        }
      });
      return emailInWatchlist;
    } catch (err) {
      captureException(err);
      throw err;
    }
  }
  async getFreeEmailDomainInWatchlist(emailDomain) {
    try {
      const domainInWatchWatchlist = await prisma.watchlist.findFirst({
        where: {
          type: WatchlistType.DOMAIN,
          value: emailDomain
        }
      });
      return domainInWatchWatchlist;
    } catch (err) {
      captureException(err);
      throw err;
    }
  }
  /** Returns a boolean if any of the users passed are blocked */
  async searchForAllBlockedRecords({
    usernames,
    emails,
    domains
  }) {
    try {
      const blockedRecords = await prisma.watchlist.findMany({
        where: {
          severity: WatchlistSeverity.CRITICAL,
          OR: [
            ...usernames.length > 0 ? [
              {
                type: WatchlistType.USERNAME,
                value: {
                  in: usernames
                }
              }
            ] : [],
            ...emails.length > 0 ? [
              {
                type: WatchlistType.EMAIL,
                value: {
                  in: emails
                }
              }
            ] : [],
            ...domains.length > 0 ? [
              {
                type: WatchlistType.DOMAIN,
                value: {
                  in: domains
                }
              }
            ] : []
          ]
        }
      });
      return blockedRecords;
    } catch (err) {
      captureException(err);
      throw err;
    }
  }
}
export {
  WatchlistRepository as W
};
