import { SupportTicket } from "../models/SupportTicket.js";

export async function createTicket(request, response) {
  const ticket = await SupportTicket.create({ ...request.body, customer: request.user._id });
  request.app.get("io").to("support").emit("ticket:created", ticket);
  response.status(201).json(ticket);
}

export async function listTickets(_request, response) {
  const tickets = await SupportTicket.find().sort("-createdAt").limit(100);
  response.json(tickets);
}
