module.exports = function (sequelize, DataTypes) {
    const UserDevice = sequelize.define('UserDevice', {
        id: {
            type: DataTypes.UUID,
            defaultValue: DataTypes.UUIDV4,
            primaryKey: true,
        },
        userId: {
            type: DataTypes.UUID,
            foreignKey: true,
            allowNull: false,
        },
        token: {
            type: DataTypes.STRING,
        },
        valid: {
            type: DataTypes.BOOLEAN,
        },        
        invalidated: {
            type: DataTypes.DATE,
        },
        platform: {
            type: DataTypes.STRING,
        },
    }, {
        tableName: 'users_devides',
        freezeTableName: true,
        timestamps: true,
    });

    UserDevice.associate = function (models) {
        UserDevice.User = UserDevice.belongsTo(models.User, {foreignKey: 'userId'  });
    };

    return UserDevice;
};
    