{#- Context variables:
   - company: str (e.g., "ACME Bank")
   - industry: str (e.g., "fsi")
   - catalog: str (e.g., "acme_fsi_demo")
   - bundle_name: str (e.g., "acme-bank-fsi-demo")
   - app_name: str (e.g., "acme-bank-fsi-app")
   - warehouse_id: str
   - workspace_host: str
   - databricks_profile: str | None
   - lakebase_url: str | None
   - notification_email: str
   - demo_title: str (e.g., "Acme Bank FSI Demo" or "Financial Services Demo")
-#}
# /plan — {{ demo_title }} Planner

**This command handles Phase 0: Research & Planning.** Run this before `/build-next`.

---

## FIRST: Check Current State

1. Read `conf/demo_manifest.json` — check if a plan already exists.
2. Read `docs/IMPLEMENTATION_PLAN.md` — does it contain real content (not just the placeholder)?

**If a real plan already exists** → Tell the user: "Plan already exists. Run `/build-next` to start building."
**If no plan exists** → Proceed with Phase 0 below.

---

## Phase 0: Research & Planning

### Step 0.1: Read All Skills FIRST

Before doing ANYTHING else, read these files thoroughly:
- `.claude/skills/databricks-spark-declarative-pipelines/` — DLT/SDP patterns
- `.claude/skills/databricks-jobs/` — Job configuration with serverless
- `.claude/skills/databricks-aibi-dashboards/` — Dashboard patterns
- `.claude/skills/databricks-asset-bundles/` — Infrastructure-as-code
- `.claude/skills/databricks-model-serving/` — Model serving patterns
- `.claude/skills/databricks-agent-bricks/` — Agent Framework patterns
- `.claude/skills/databricks-synthetic-data-generation/` — Data generation techniques

**These files contain critical knowledge. Read them before planning.**

### Step 0.2: Research the Company & Industry

Use web search to research:
- **{{ display_name }}** — What do they do? What are their key challenges? What data do they work with?
- **{{ industry | upper }} industry** — Common data patterns, regulatory requirements, key metrics
- **Databricks {{ industry }} use cases** — What demos resonate with {{ industry }} buyers?

Synthesize this into 2-3 compelling demo scenarios.

### Step 0.3: Ask Clarifying Questions

**IMPORTANT: Ask these questions BEFORE planning. Do NOT assume.**

1. What specific use cases should this demo showcase? *(Suggest 2-3 based on your research)*
2. What data entities make sense? *(Suggest 5-10 tables with relationships)*
3. What size demo? (Quick: 3-4 tables, Standard: 5-7 tables, Comprehensive: 8-10 tables)
4. What ML model type? (Classification vs Regression — suggest based on industry)
5. What KPIs should the dashboard highlight? *(Suggest 5-10 based on industry)*
6. What should the showcase app do? *(Suggest 2-3 app ideas)*
7. Data volume preferences? (Default: 100K-500K rows per table)
8. Any specific talk track themes or audience considerations?

**Wait for answers before proceeding.**

### Step 0.4: Create Implementation Plan

After user answers, create `docs/IMPLEMENTATION_PLAN.md` with:

```markdown
# {{ demo_title }} — Implementation Plan

## Use Case Description
[What business problem we're solving, why it matters to {{ display_name }}]

## Data Schema
| Table | Description | Key Columns | Rows | Layer |
|-------|------------|-------------|------|-------|
| ... | ... | ... | ... | raw -> bronze -> silver |

### Relationships
[Foreign keys, dimensional model, fact/dimension identification]

## Data Generation Strategy
- Structured: [entities, volumes, Faker strategies]
- Unstructured: [PDFs, documents for RAG — what content]

## DLT Pipeline Structure
### Bronze
[List of streaming tables with read_files sources]
### Silver
[List of streaming tables with quality constraints]
### Gold
[List of materialized views with business aggregations]

## ML Model
- **Type**: [Classification / Regression]
- **Target**: [What we're predicting]
- **Features**: [Key features from gold tables]
- **Business value**: [Why this prediction matters]

## Dashboard Design
### Executive Dashboard
- KPI 1: [metric + visualization type]
- KPI 2: ...
### Operational Dashboard (if applicable)
- ...

## Genie Space
- [What questions should users be able to ask in natural language]

## Agent Use Case
- **Purpose**: [What the agent does — e.g., compliance assistant, fraud investigator]
- **Knowledge sources**: [What unstructured data it uses]
- **Tools**: [What UC functions it calls]

## Showcase App
- **Purpose**: [What the app does — e.g., fraud investigation workbench]
- **Key pages**: [List of pages with descriptions]
- **Data sources**: [Gold tables, ML model endpoints, Lakebase tables]

## Execution Timeline
| Wave | What | Estimated Time |
|------|------|---------------|
| 1 | Data Foundation | 10-15 min |
| 2 | DLT Pipelines | 15-20 min |
| 3 | ML + Dashboards | 15-20 min |
| 4 | Showcase App | 30-45 min |
| 5 | Agents + Polish | 15-20 min |
```

### Step 0.5: Get Approval

**STOP and present this plan to the user.**

Ask: "Does this plan look good? Any adjustments?"

**This is the ONLY mandatory human gate. Everything after runs with governance.**

After approval, update `conf/demo_manifest.json`:
- Populate the `schemas` field with planned table definitions
- Add the approved plan summary to `talk_track_hints`
- Add a decision: "Implementation plan approved on [date]"

### Step 0.6: Apply Plan to Scaffold Placeholders

After the plan is approved, update scaffold files with plan-specific values:

1. **`databricks.yml`** — set variable defaults:
   - `schema` -> the ML/analytics schema name from the plan
   - `pipeline_target_schema` -> the DLT target schema from the plan

2. **`resources/jobs/data_generation_job.yml`** — add one task per entity:
   - Create `depends_on` DAG from foreign key relationships in the plan
   - Every task depends on `setup_catalog`; child entities depend on parents

3. **`resources/pipelines/main_pipeline.yml`** — verify catalog and target are set

4. **`conf/demo_manifest.json`** — populate `schemas` field with planned tables

5. **`requirements.txt`** — add domain-specific packages if needed

6. **`src/data_generation/setup_catalog.py`** — update the `schemas` list with the planned schema names

Run `databricks bundle validate` after these changes to confirm everything resolves.

---

Plan approved. Run `/build-next` to start building.
