# Example: JSONata transformation for CSV pipeline
# Use with the same extract (input.csv) and load (output.csv) as the simple transform.
# Paste this into the Transform config panel in the ETL UI instead of transform.yaml.
#
# JSONata docs: https://jsonata.org/

jsonata:
  mode: record

  # Per-record transformation. Input fields: product_id, product_name, category, price, quantity, updated_at
  expression: |
    {
      "id": product_id,
      "name": product_name,
      "category": $uppercase(category),
      "unit_price": $number(price),
      "quantity": $number(quantity),
      "line_total": $round($number(price) * $number(quantity), 2),
      "category_group": (
        category = "Electronics" or category = "Accessories" ? "Tech" :
        category = "Hardware" ? "Industrial" : "Other"
      ),
      "updated_at": updated_at,
      "processed_at": $now(),
      "name_slug": $lowercase(product_name)
    }
