How to take rules as inputs from user?

I am creating an automation tool which helps users in automating various tasks such as sending top-performing products, outlets, etc. I am stuck in the planning phase as what kind of user interface I will need so a user can define rules.

I have so far come up with the following approach,
I will have all columns name into a component, so the user can make expressions using components and pre-defined operators. Now those are base components, I want to allow the user to create programmable components, with which user can define the definition of it and can access the value of this component this in other components making.

Base components will be like,

  • Item Price
  • Item sold qty
  • Item current qty
  • Item stock
  • Item margin

Programmable components can be of like,

  • Top performing item
    Max of (sold qty * margin)
  • OOS soon items
    Min of (current qty + stock)

Programmable components can be anything similar to the user can query on the same database, so should I use query language similar approach to take inputs or?

Thanks