{#- Context variables:
   - catalog: str (e.g., "acme_fsi_demo")
   - demo_title: str (e.g., "Acme Bank FSI Demo")
-#}
# Databricks notebook source

# COMMAND ----------

# MAGIC %md
# MAGIC # {{ demo_title }} — Sample Data Generation
# MAGIC
# MAGIC Generates a small sample dataset to verify the end-to-end pipeline works.
# MAGIC This file is replaced by `/plan` + `/build-next` with real industry-specific generators.

# COMMAND ----------

dbutils.widgets.text("catalog", "{{ catalog }}")
catalog = dbutils.widgets.get("catalog")

# COMMAND ----------

from pyspark.sql import functions as F
from pyspark.sql.types import StructType, StructField, StringType, IntegerType, DoubleType, DateType
import datetime

# Simple sample data — no external dependencies needed
data = []
for i in range(100):
    data.append({
        "customer_id": f"CUST-{i:04d}",
        "name": f"Customer {i}",
        "email": f"customer{i}@example.com",
        "age": 25 + (i % 50),
        "balance": round(1000.0 + (i * 123.45) % 50000, 2),
        "risk_score": round(0.1 + (i * 0.37) % 0.9, 3),
        "signup_date": str(datetime.date(2024, 1, 1) + datetime.timedelta(days=i % 365)),
    })

df = spark.createDataFrame(data)
print(f"Generated {df.count()} sample customers")
df.show(5)

# COMMAND ----------

# Write to landing volume
VOLUME_PATH = f"/Volumes/{catalog}/default/landing/customers"
df.repartition(1).write.mode("overwrite").parquet(VOLUME_PATH)
print(f"Written to {VOLUME_PATH}")
