import { y as defineEventHandler, b0 as useLogger, aG as readValidatedBody, a as APUser, I as Instance, v as createError, a$ as unfollowActor, W as followActor } from '../../../nitro/nitro.mjs';
import { r as requireAdminSession } from '../../../_/session.mjs';
import { z } from 'zod';
import 'luxon';
import '@sequelize/core';
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({
  ap_id: z.string()
});
const follow_put = defineEventHandler(async (event) => {
  await requireAdminSession(event);
  const log = useLogger("follow");
  const { ap_id } = await readValidatedBody(event, schema.parse);
  const ap_actor = await APUser.findByPk(ap_id, { include: Instance });
  if (!ap_actor) {
    log.warn("This ap user does not exists: ", ap_id);
    throw createError({ status: 404, message: "This ap user does not exists" });
  }
  if (ap_actor.following) {
    return unfollowActor(ap_actor);
  } else {
    return followActor(ap_actor);
  }
});

export { follow_put as default };
