import { DiaryTag, DiaryDateTag } from '../models/index.js';

export const getTags = async (req, res) => {
    try {
        const tags = await DiaryTag.findAll();
        res.status(200).json(tags);
    } catch (error) {
        res.status(500).json({ error: 'Error fetching tags' });
    }
};

export const createTag = async (req, res) => {
    try {
        const { name } = req.body;
        console.log(name);
        const newTag = await DiaryTag.findOrCreate({ where: { name }, defaults: { name } });
        res.status(201).json(newTag);
    } catch (error) {
        console.log('[createTag] - Error:', error);
        res.status(500).json({ error: 'Error creating tag' });
    }
};

export const deleteTag = async (req, res) => {
    try {
        const { tagId } = req.params;
        const { authcode: userToken } = req.headers;
        const { clubId } = req.params;
        await diaryService.removeTagFromDiaryDate(userToken, clubId, tagId);
        res.status(200).json({ message: 'Tag deleted' });
    } catch (error) {
        console.error('[deleteTag] - Error:', error);
        res.status(500).json({ error: 'Error deleting tag' });
    }
};
