# /// script
# requires-python = ">=3.11"
# dependencies = [
{% for dep in deps %}#     "{{ dep }}",
{% endfor %}
# ]
# ///
"""
Feature Group: {{ name }}

Generated by: seeknal draft feature-group {{ name }} --python
"""

from seeknal.pipeline import feature_group
from seeknal.pipeline.materialization import Materialization, OfflineConfig


@feature_group(
    name="{{ name }}",
    entity="user",  # Entity name for joins (e.g., "user", "product")
    description="{{ description or 'Feature group for user entity' }}",
    materialization=Materialization(
        offline=OfflineConfig(format="parquet"),
        # online=OnlineConfig(enabled=True, ttl_seconds=3600),
    ),
    # inputs=["transform.clean_data"],  # Upstream dependencies
    # features={  # Optional feature schema
    #     "feature1": {"dtype": "int", "description": "Feature 1"},
    #     "feature2": {"dtype": "float", "description": "Feature 2"},
    # },
)
def {{ name }}(ctx):
    """
    Feature group function receives context with:
    - ctx.ref("kind.name") -> Get upstream DataFrame
    - ctx.duckdb -> DuckDB connection
    - ctx.config -> Profile configuration

    Return the feature DataFrame.
    """
    df = ctx.ref("transform.clean_data")  # Reference upstream node

    # Build features using SQL
    return ctx.duckdb.sql("""
        SELECT
            user_id,
            COUNT(*) as total_events,
            AVG(session_duration) as avg_session_duration
        FROM df
        GROUP BY user_id
    """).df()
