import type { Request, Response } from 'express';
import ContentCatalogService from '@/services/content_catalog';

export async function list(req: Request, res: Response): Promise<void> {
  const payload = await ContentCatalogService.list(req.query, req.currentUser);
  res.status(200).send(payload);
}

export async function create(req: Request, res: Response): Promise<void> {
  const payload = await ContentCatalogService.create(
    req.body.data,
    req.currentUser,
  );
  res.status(201).send(payload);
}

export async function findManagedByType(
  req: Request,
  res: Response,
): Promise<void> {
  const payload = await ContentCatalogService.findManagedByType(
    req.params.contentType,
    req.currentUser,
  );
  res.status(200).send(payload);
}

export async function update(req: Request, res: Response): Promise<void> {
  const payload = await ContentCatalogService.update(
    req.params.contentType,
    req.body.data,
    req.currentUser,
  );
  res.status(200).send(payload);
}

export async function remove(req: Request, res: Response): Promise<void> {
  await ContentCatalogService.delete(req.params.contentType, req.currentUser);
  res.status(204).send();
}
