import { y as defineEventHandler, ac as getValidatedQuery, am as jsonPath, R as Resource } from '../../../nitro/nitro.mjs';
import { r as requireAdminSession } from '../../../_/session.mjs';
import z from 'zod';
import { Op, where, fn, sql } from '@sequelize/core';
import 'luxon';
import 'html-to-text';
import 'crypto';
import 'node:fs';
import 'sharp';
import 'path';
import 'node:stream';
import 'jsdom';
import 'dompurify';
import 'mime-types';
import 'fs';
import 'fs/promises';
import 'linkify-html';
import '@peertube/http-signature';
import 'jsonld';
import 'lodash.intersection';
import 'email-templates';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'node:events';
import 'node:buffer';
import 'node:path';
import 'vue';
import 'vue-router';
import 'dotenv';
import 'url';
import 'bcryptjs';
import 'slugify';
import 'umzug';
import 'consola';
import '@sequelize/core/decorators-legacy';
import 'util';
import 'mitt';
import 'ical.js';
import 'node:url';
import 'fast-xml-parser';
import '../../../_/getUser.mjs';
import '../../../_/jwt.mjs';
import 'jose';

const schema = z.object({
  page: z.coerce.number().min(1).default(1),
  pageSize: z.coerce.number().min(5).max(50).default(15),
  query: z.string().optional()
});
const index_get = defineEventHandler(async (evt) => {
  await requireAdminSession(evt);
  const params = await getValidatedQuery(evt, schema.parse);
  const andWhere = [];
  if (params.query) {
    andWhere.push({
      [Op.or]: [
        where(fn("LOWER", jsonPath("data", ["content"])), Op.like, "%" + params.query + "%"),
        where(fn("LOWER", sql.attribute("apUserApId")), Op.like, "%" + params.query + "%"),
        where(fn("LOWER", sql.attribute("$event.title$")), Op.like, "%" + params.query + "%")
      ]
    });
  }
  const result = await Resource.findAndCountAll({
    include: [
      { association: "APUser", attributes: ["ap_id", "object", "blocked"] },
      { association: "event", attributes: ["id", "title", "slug"] }
    ],
    where: andWhere,
    offset: (params.page - 1) * params.pageSize,
    limit: params.pageSize,
    order: [["createdAt", "DESC"]]
  });
  return {
    data: result.rows,
    count: result.count,
    totalPages: Math.ceil(result.count / params.pageSize)
  };
});

export { index_get as default };
