const Service = require("../model/Service");
const generateSequence = require("../utils/generateSequence");

const createService = async (req, res) => {
  try {
    const serviceCode = await generateSequence("service", "SVC");
    const service = await Service.create({ ...req.body, serviceCode });
    return res.status(201).json(service);
  } catch (error) {
    return res.status(400).json({ message: error.message });
  }
};

const getServices = async (_req, res) => {
  const services = await Service.find().sort({ serviceName: 1 });
  return res.json(services);
};

module.exports = { createService, getServices };
