"use strict";
const Sentry = require("@sentry/nextjs");
const index = require("./i18n-Bs8xJzoY.cjs");
class WatchlistRepository {
  async getBlockedEmailInWatchlist(email) {
    const [, domain] = email.split("@");
    try {
      const emailInWatchlist = await index.prisma.watchlist.findFirst({
        where: {
          severity: index.WatchlistSeverity.CRITICAL,
          OR: [
            { type: index.WatchlistType.EMAIL, value: email },
            { type: index.WatchlistType.DOMAIN, value: domain }
          ]
        }
      });
      return emailInWatchlist;
    } catch (err) {
      Sentry.captureException(err);
      throw err;
    }
  }
  async getFreeEmailDomainInWatchlist(emailDomain) {
    try {
      const domainInWatchWatchlist = await index.prisma.watchlist.findFirst({
        where: {
          type: index.WatchlistType.DOMAIN,
          value: emailDomain
        }
      });
      return domainInWatchWatchlist;
    } catch (err) {
      Sentry.captureException(err);
      throw err;
    }
  }
  /** Returns a boolean if any of the users passed are blocked */
  async searchForAllBlockedRecords({
    usernames,
    emails,
    domains
  }) {
    try {
      const blockedRecords = await index.prisma.watchlist.findMany({
        where: {
          severity: index.WatchlistSeverity.CRITICAL,
          OR: [
            ...usernames.length > 0 ? [
              {
                type: index.WatchlistType.USERNAME,
                value: {
                  in: usernames
                }
              }
            ] : [],
            ...emails.length > 0 ? [
              {
                type: index.WatchlistType.EMAIL,
                value: {
                  in: emails
                }
              }
            ] : [],
            ...domains.length > 0 ? [
              {
                type: index.WatchlistType.DOMAIN,
                value: {
                  in: domains
                }
              }
            ] : []
          ]
        }
      });
      return blockedRecords;
    } catch (err) {
      Sentry.captureException(err);
      throw err;
    }
  }
}
exports.WatchlistRepository = WatchlistRepository;
