import predefinedActivityService from '../services/predefinedActivityService.js';

export const createPredefinedActivity = async (req, res) => {
    try {
        const { name, description, durationText, duration } = req.body;
        const predefinedActivity = await predefinedActivityService.createPredefinedActivity({ name, description, durationText, duration });
        res.status(201).json(predefinedActivity);
    } catch (error) {
        console.error('[createPredefinedActivity] - Error:', error);
        res.status(500).json({ error: 'Error creating predefined activity' });
    }
};

export const getAllPredefinedActivities = async (req, res) => {
    try {
        const predefinedActivities = await predefinedActivityService.getAllPredefinedActivities();
        res.status(200).json(predefinedActivities);
    } catch (error) {
        console.error('[getAllPredefinedActivities] - Error:', error);
        res.status(500).json({ error: 'Error fetching predefined activities' });
    }
};

export const getPredefinedActivityById = async (req, res) => {
    try {
        const { id } = req.params;
        const predefinedActivity = await predefinedActivityService.getPredefinedActivityById(id);
        if (!predefinedActivity) {
            return res.status(404).json({ error: 'Predefined activity not found' });
        }
        res.status(200).json(predefinedActivity);
    } catch (error) {
        console.error('[getPredefinedActivityById] - Error:', error);
        res.status(500).json({ error: 'Error fetching predefined activity' });
    }
};

export const updatePredefinedActivity = async (req, res) => {
    try {
        const { id } = req.params;
        const { name, description, durationText, duration } = req.body;
        const updatedActivity = await predefinedActivityService.updatePredefinedActivity(id, { name, description, durationText, duration });
        res.status(200).json(updatedActivity);
    } catch (error) {
        console.error('[updatePredefinedActivity] - Error:', error);
        res.status(500).json({ error: 'Error updating predefined activity' });
    }
};
