{
        "description": "Check for expired quotations and update status",
        "trigger": {
            "event": "schedule:daily",
            "schedule": "0 2 * * *",
            "description": "Run at 2 AM daily"
        },
        "steps": [
            {
                "order": 1,
                "type": "query",
                "sql": "SELECT quotation_id, quotation_number, customer_id, created_by FROM quotations WHERE status = 'sent' AND expires_at < NOW() AND NOT isDeleted",
                "outputVar": "expired_quotations",
                "description": "Find all expired quotations"
            },
            {
                "order": 2,
                "type": "foreach",
                "collection": "{expired_quotations}",
                "steps": [
                    {
                        "type": "update",
                        "table": "quotations",
                        "fields": {
                            "status": "expired"
                        },
                        "where": {
                            "quotation_id": "{item.quotation_id}"
                        }
                    },
                    {
                        "type": "notification",
                        "recipients": ["{item.created_by}"],
                        "template": "quotation_expired",
                        "data": {
                            "quotation_number": "{item.quotation_number}",
                            "customer_id": "{item.customer_id}"
                        },
                        "channels": ["email"]
                    },
                    {
                        "type": "emit",
                        "event": "quotation:expired",
                        "data": {
                            "quotation_id": "{item.quotation_id}"
                        }
                    }
                ]
            },
            {
                "order": 3,
                "type": "audit",
                "action": "quotations_expired",
                "data": {
                    "count": "{expired_quotations.length}",
                    "quotation_ids": "{expired_quotations.map(q => q.quotation_id)}"
                }
            }
        ]
    }