# /// script
# requires-python = ">=3.11"
# dependencies = [
#     "pandas",
#     "duckdb",
# {% for dep in deps %}#     "{{ dep }}",
# {% endfor %}
# ]
# ///
"""
Second-Order Aggregation: {{ name }}

Generated by: seeknal draft second-order-aggregation {{ name }} --python
"""

from seeknal.pipeline import second_order_aggregation


@second_order_aggregation(
    name="{{ name }}",
    id_col="{{ id_col or 'region_id' }}",
    feature_date_col="{{ feature_date_col or 'date' }}",
    application_date_col="{{ application_date_col or 'application_date' }}",
    description="{{ description or 'Second-order aggregation of aggregated features' }}",
    features={
        # TODO: Define your aggregation features here
        # Each key is a column from the upstream source to aggregate.
        # Values specify aggregation types: basic, window, ratio.
        #
        # "daily_amount": {
        #     "basic": ["sum", "mean", "max", "stddev"],
        #     "window": {"windows": [7, 30], "functions": ["mean", "sum"]},
        # },
        # "daily_count": {
        #     "basic": ["sum", "mean"],
        # },
    },
    # materialization={
    #     "type": "iceberg",
    #     "table": "warehouse.analytics.{{ name }}",
    # },
)
def {{ name }}(ctx):
    """Load data for SOA engine — the engine handles aggregation.

    Return the upstream DataFrame via ctx.ref(). The built-in SOA engine
    will automatically apply the declared aggregations.
    """
    return ctx.ref("{{ source_ref or 'transform.upstream_aggregation' }}")
