import asyncHandler from '../utils/asyncHandler.js';
import staffService from '../services/staffService.js';

export const list = asyncHandler(async (req, res) => {
  const staff = await staffService.listStaff(req.query);
  res.status(200).json({ success: true, data: { staff } });
});

export const getOne = asyncHandler(async (req, res) => {
  const staff = await staffService.getStaff(req.params.id);
  res.status(200).json({ success: true, data: { staff } });
});

export const create = asyncHandler(async (req, res) => {
  const staff = await staffService.createStaff(req.body, req);
  res.status(201).json({ success: true, message: 'Staff member created', data: { staff } });
});

export const update = asyncHandler(async (req, res) => {
  const staff = await staffService.updateStaff(req.params.id, req.body, req);
  res.status(200).json({ success: true, message: 'Staff member updated', data: { staff } });
});

export const setStatus = asyncHandler(async (req, res) => {
  const staff = await staffService.setStatus(req.params.id, req.body.status, req);
  res.status(200).json({ success: true, message: `Staff member ${staff.status.toLowerCase()}`, data: { staff } });
});

export const remove = asyncHandler(async (req, res) => {
  await staffService.deleteStaff(req.params.id, req);
  res.status(200).json({ success: true, message: 'Staff member deleted' });
});

export const permissions = asyncHandler(async (req, res) => {
  res.status(200).json({ success: true, data: staffService.getPermissionsMatrix(req.user.role) });
});
