import { DataTypes } from 'sequelize';
import sequelize from '../database.js';
import Member from './Member.js';

const DiaryTag = sequelize.define('DiaryTag', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false,
    },
    name: {
        type: DataTypes.STRING,
        allowNull: false,
        unique: true,
    },
}, {
    underscored: true,
    tableName: 'diary_tags',
    timestamps: true,
});

const MemberDiaryTag = sequelize.define('MemberDiaryTag', {
    memberId: {
        type: DataTypes.INTEGER,
        references: {
            model: Member,
            key: 'id',
        },
        onDelete: 'CASCADE',
    },
    tagId: {
        type: DataTypes.INTEGER,
        references: {
            model: DiaryTag,
            key: 'id',
        },
        onDelete: 'CASCADE',
    },
}, {
    underscored: true,
    tableName: 'member_diary_tags',
    timestamps: true,
});

export { DiaryTag, MemberDiaryTag };
