import AppError from "../../errors/AppError";
import Position from "../../models/Position";
import AssociateQuickAnswerQueue from "../QueueService/AssociateQuickAnswerQueue";

interface Request {
  name: string;
}

const CreatePositionService = async ({ name }: Request): Promise<Position> => {
  const nameExists = await Position.findOne({
    where: { name }
  });

  if (nameExists) {
    throw new AppError("ERR_POSITION_DUPLICATED");
  }

  const position = await Position.create({ name });

  return position;
};

export default CreatePositionService;
