module.exports = function (sequelize, DataTypes) {
    const Notification = sequelize.define('Notification', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true,
        },
        date: {
            type: DataTypes.DATE,
            allowNull: false,
        }, 
        title: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        body: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        ttl: {
            type: DataTypes.INTEGER,
            allowNull: true,
        },
        priority: {
            type: DataTypes.STRING,
            allowNull: false,
            default: 'default',
        },
        recipients: {
            type: DataTypes.JSON,
            allowNull: true,
        },
        data: {
            type: DataTypes.JSON,
            allowNull: true,
        },
    }, {
        tableName: 'notifications',
        freezeTableName: true,
        timestamps: true,
    });

    Notification.associate = function (models) {
        Notification.User = Notification.belongsTo(models.User, { foreignKey: 'userId', as: "user" });
        Notification.Details = Notification.hasMany(models.NotificationDetail, { foreignKey: 'notificationId', as: 'details' });
    };

    return Notification;
};
    