const MarbleSpace = require("../models/MarbleSpace");

exports.createMarbleSpace = async (req, res) => {
  try {
    const marbleSpace = await MarbleSpace.create({
      name: req.body.name,
    });

    res.status(201).json({
      success: true,
      marbleSpace,
    });
  } catch (error) {
    res.status(500).json({
      message: error.message,
    });
  }
};

exports.getMarbleSpaces = async (req, res) => {
  try {
    const data = await MarbleSpace.find().sort({
      _id: -1,
    });

    res.json(data);
  } catch (error) {
    res.status(500).json({
      message: error.message,
    });
  }
};

exports.getMarbleSpace = async (req, res) => {
  try {
    const data = await MarbleSpace.findById(req.params.id);

    res.json(data);
  } catch (error) {
    res.status(500).json({
      message: error.message,
    });
  }
};

exports.updateMarbleSpace = async (req, res) => {
  try {
    await MarbleSpace.findByIdAndUpdate(req.params.id, {
      name: req.body.name,
    });

    res.json({
      success: true,
    });
  } catch (error) {
    res.status(500).json({
      message: error.message,
    });
  }
};

exports.deleteMarbleSpace = async (req, res) => {
  try {
    await MarbleSpace.findByIdAndDelete(req.params.id);

    res.json({
      success: true,
    });
  } catch (error) {
    res.status(500).json({
      message: error.message,
    });
  }
};
