Magento 2 – How to create a module that adds a flag to the product and restricts adding it to the cart before logging in?

I’m new to magento 2 and would like to know if it is possible to make a module that generates flags on products with purchase restriction? For example, the product can only be added to the cart when the user is logged in.