---
name: step-00-init
description: Initialize controller generation - parse arguments, validate inputs, setup state
next_step: steps/step-01-analyze.md
---

# Step 0: Initialization

## MANDATORY EXECUTION RULES:

- NEVER skip argument parsing
- ALWAYS validate area is valid (Admin, Support, Business, User, Auth)
- YOU ARE AN INITIALIZER, not a generator
- FORBIDDEN to load step-01 until init is complete

## YOUR TASK:

Parse arguments, validate inputs, and initialize state variables for controller generation.

---

<defaults>
## Default Configuration

```yaml
auto_mode: false      # -a: Skip confirmations
postman_mode: false   # -p: Generate Postman tests
dto_mode: false       # -d: Generate DTOs
interactive_mode: false # -i: Configure via menu
```
</defaults>

---

## EXECUTION SEQUENCE:

### 1. Parse Flags and Input

**Step 1: Load defaults from config above**

```
{auto_mode}        = false
{postman_mode}     = false
{dto_mode}         = false
{interactive_mode} = false
```

**Step 2: Parse user input and override defaults:**

```
Enable flags (lowercase - turn ON):
  -a or --auto      -> {auto_mode} = true
  -p or --postman   -> {postman_mode} = true
  -d or --dtos      -> {dto_mode} = true
  -i or --interactive -> {interactive_mode} = true

Disable flags (UPPERCASE - turn OFF):
  -A or --no-auto     -> {auto_mode} = false
  -P or --no-postman  -> {postman_mode} = false
  -D or --no-dtos     -> {dto_mode} = false

Arguments (after flags removed):
  First word  -> {area}
  Second word -> {module}
  Third word  -> {entity} (optional, default = singularize({module}))
```

### 2. Validate Area

**Valid areas:**

| Area | Route Resolution | Permission Path Prefix |
|------|-----------------|----------------------|
| `Admin` | NavRoute(`administration.{module}`) | `administration.` |
| `Support` | NavRoute(`support.{module}`) | `support.` |
| `Business` | NavRoute(`{application}.{module}`) | `{application}.` |
| `User` | NavRoute(`myspace.{module}`) | `myspace.` |
| `Auth` | `api/auth/` | (AllowAnonymous) |

> **Note:** All areas except Auth use `[NavRoute]` for dynamic route resolution from the navigation database. There are no hardcoded API prefixes like `api/business/`.

**If {area} missing or invalid:**

```yaml
AskUserQuestion:
  header: "Area"
  question: "Which area for the controller?"
  options:
    - label: "Admin"
      description: "Administration controllers (NavRoute)"
    - label: "Support"
      description: "Support features (NavRoute)"
    - label: "Business"
      description: "Business application modules (NavRoute)"
    - label: "User"
      description: "User-facing features (NavRoute)"
```

### 3. Validate Module

**If {module} missing:**

```yaml
AskUserQuestion:
  header: "Module"
  question: "What is the module name? (PascalCase, e.g., Tickets, Users)"
  # Free text input
```

**Normalize:**
- Convert to PascalCase
- Example: "tickets" → "Tickets", "user-roles" → "UserRoles"

### 4. Derive Entity Name

**If {entity} not provided:**

```
{entity} = singularize({module})

Examples:
  Users → User
  Tickets → Ticket
  Categories → Category
  SlaDefinitions → SlaDefinition
```

### 5. Compute Permission Path

**Based on {area}:**

```
Admin    → {permission_path} = "administration.{module_lowercase}"
Support  → {permission_path} = "support.{module_lowercase}"
Business → {permission_path} = "{application_lowercase}.{module_lowercase}"
User     → {permission_path} = "myspace.{module_lowercase}"
Auth     → {permission_path} = null (AllowAnonymous)
```

### 6. Interactive Mode (if -i flag)

If `{interactive_mode}` = true:

```yaml
questions:
  - header: "Configure"
    question: "Select options for controller generation:"
    options:
      - label: "Auto mode (-a)"
        description: "Skip all confirmations"
      - label: "Postman tests (-p)"
        description: "Generate Postman test collection"
      - label: "DTOs (-d)"
        description: "Generate CreateDto, UpdateDto, ResponseDto"
    multiSelect: true
```

### 7. Show Summary and Proceed

**Always show COMPACT summary:**

```
Controller: {area}/{module}Controller

| Variable | Value |
|----------|-------|
| {area} | Admin |
| {module} | Users |
| {entity} | User |
| {permission_path} | administration.users |
| {auto_mode} | true/false |
| {postman_mode} | true/false |
| {dto_mode} | true/false |

-> Analyzing codebase...
```

**Then proceed directly to step-01-analyze.md**

---

## SUCCESS METRICS:

- All arguments correctly parsed
- Area validated against allowed values
- Module/Entity derived correctly
- Permission path computed
- Output is COMPACT (one table)
- Proceeded to step-01 immediately after summary

## NEXT STEP:

After showing initialization summary, always proceed directly to `./step-01-analyze.md`
