import PredefinedActivity from '../models/PredefinedActivity.js';

class PredefinedActivityService {
    async createPredefinedActivity(data) {
        console.log('[PredefinedActivityService::createPredefinedActivity] - Creating predefined activity');
        return await PredefinedActivity.create({
            name: data.name,
            description: data.description,
            durationText: data.durationText,
            duration: data.duration,
        });
    }

    async updatePredefinedActivity(id, data) {
        console.log(`[PredefinedActivityService::updatePredefinedActivity] - Updating predefined activity with id: ${id}`);
        const activity = await PredefinedActivity.findByPk(id);
        if (!activity) {
            console.log('[PredefinedActivityService::updatePredefinedActivity] - Activity not found');
            throw new Error('Predefined activity not found');
        }
        return await activity.update({
            name: data.name,
            description: data.description,
            durationText: data.durationText,
            duration: data.duration,
        });
    }

    async getAllPredefinedActivities() {
        console.log('[PredefinedActivityService::getAllPredefinedActivities] - Fetching all predefined activities');
        return await PredefinedActivity.findAll();
    }

    async getPredefinedActivityById(id) {
        console.log(`[PredefinedActivityService::getPredefinedActivityById] - Fetching predefined activity with id: ${id}`);
        const activity = await PredefinedActivity.findByPk(id);
        if (!activity) {
            console.log('[PredefinedActivityService::getPredefinedActivityById] - Activity not found');
            throw new Error('Predefined activity not found');
        }
        return activity;
    }
}

export default new PredefinedActivityService();
