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

export interface WorkNoteAttachmentAttributes {
    id: string;
    noteId: string;
    documentId: string;
    documentType: string;
}

export interface WorkNoteAttachmentInstance extends Model<WorkNoteAttachmentAttributes>, WorkNoteAttachmentAttributes { }

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

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

    return WorkNoteAttachment;
};
