const IsoTask = require('../models/IsoTask');

exports.getAll = (req, res) => {
    const { category, status } = req.query;
    const data = IsoTask.getAll({ category, status });
    res.json({ success: true, data });
};

exports.getOne = (req, res) => {
    const task = IsoTask.getById(req.params.id);
    if (!task) return res.status(404).json({ success: false, message: 'Nicht gefunden' });
    res.json({ success: true, data: task });
};

exports.create = (req, res) => {
    const task = IsoTask.create(req.body);
    res.status(201).json({ success: true, data: task });
};

exports.update = (req, res) => {
    const task = IsoTask.update(req.params.id, req.body);
    if (!task) return res.status(404).json({ success: false, message: 'Nicht gefunden' });
    res.json({ success: true, data: task });
};

exports.remove = (req, res) => {
    const ok = IsoTask.delete(req.params.id);
    if (!ok) return res.status(404).json({ success: false, message: 'Nicht gefunden' });
    res.json({ success: true });
};
