module.exports = function (sequelize, DataTypes) {
    const NotificationDetail = sequelize.define('NotificationDetail', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true,
        },
        token: {
            type: DataTypes.STRING,
            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',
        },
        data: {
            type: DataTypes.JSON,
            allowNull: true,
        },
        ticket: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        deliveryDate: {
            type: DataTypes.DATE,
            allowNull: false,
            default: DataTypes.NOW,
        },
        deliveryStatus: {
            type: DataTypes.STRING,
            allowNull: true,
        },   
        receiptDate: {
            type: DataTypes.DATE,
            allowNull: true,
        },
        receiptStatus: {
            type: DataTypes.STRING,
            allowNull: true,
        },   
    }, {
        tableName: 'notifications_details',
        freezeTableName: true,
        timestamps: true,
    });

    NotificationDetail.addScope('onlyWithoutReceipt', () => {
        return {
            where: {
                receiptDate: { [Sequelize.Op.ne]: null }            
            }
        }
    });


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

    return NotificationDetail;
};
    