import { Model, DataTypes, Sequelize } from 'sequelize';

export interface WorkNoteTagAttributes {
    id: string;
    noteId: string;
    tagName: string;
}

export interface WorkNoteTagInstance extends Model<WorkNoteTagAttributes>, WorkNoteTagAttributes { }

export default (sequelize: Sequelize) => {
    const WorkNoteTag = sequelize.define<WorkNoteTagInstance>('WorkNoteTag', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true
        },
        noteId: {
            type: DataTypes.UUID,
            allowNull: false,
            references: {
                model: 'worknotes',
                key: 'id'
            }
        },
        tagName: {
            type: DataTypes.STRING,
            allowNull: false
        }
    }, {
        tableName: 'work_note_tags',
        timestamps: true,
        updatedAt: false
    });

    (WorkNoteTag as any).associate = (models: any) => {
        WorkNoteTag.belongsTo(models.Worknote, { foreignKey: 'noteId', as: 'workNote' });
    };

    return WorkNoteTag;
};
