# Navigation: Fallback Procedure (When MCP Unavailable)

> Reference for step-01-navigation.md — generates navigation seeds following SmartStack.app patterns.
> Reference: `templates-seed.md` for code templates.
>
> **Branch by Project Type:**
> - If `{seeding_strategy}` = "hasdata" (core project): Follow F1-F8 below
> - If `{seeding_strategy}` = "provider" (client project): Follow **CLIENT PROJECT HANDLING** in step file

## F1. Read Existing Configuration Files

**CRITICAL:** Before generating any code, read existing files to determine state:

1. **Find the Navigation Configuration directory:**
   ```
   Glob: **/Persistence/Configurations/Navigation/Navigation*Configuration.cs
   ```

2. **Read NavigationTranslationConfiguration.cs** - Check existing translations:
   ```
   All translation IDs use Guid.NewGuid() — no sequence to track.
   Just verify no duplicate EntityType+EntityId+LanguageCode combinations.
   ```

3. **Read Navigation{Level}Configuration.cs** - Check existing entities:
   ```
   Read the Configuration for the target level (Application, Module, Section, Resource).
   Check if it already references a SeedData class: builder.HasData(Navigation{Level}SeedData.GetSeedData())
   If yes: Read the corresponding SeedData class to find existing entries.
   If no: You will need to add HasData() call.
   ```

4. **Read existing SeedData files** (if they exist):
   ```
   Glob: **/Seeding/Data/Navigation/Navigation{Level}SeedData.cs
   Check for existing entity IDs to avoid collisions.
   ```

## F2. Determine Parent GUID

For non-application levels, find the parent entity GUID:

| Level | Parent | Where to Find Parent GUID |
|-------|--------|---------------------------|
| application | (none — top level) | — |
| module | application | `NavigationApplicationSeedData.cs` → e.g. `AdministrationAppId` |
| section | module | `NavigationModuleSeedData.cs` → e.g. `UsersModuleId` |

Read the parent SeedData class and find the GUID matching `{parent_path}`.

## F3. Generate Navigation Entity GUID

Generate a random GUID for the new navigation entity:

```csharp
// IMPORTANT: Use a stable GUID. Never change after the first seed.
// Generate once with Guid.NewGuid(), then hardcode the result as a static field.
public static readonly Guid MyEntityId = Guid.Parse("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
```

**Rules:**
- Generate a GUID once with `Guid.NewGuid()`, then **hardcode it as a static readonly field**
- NEVER call `Guid.NewGuid()` at runtime in seed data — each migration run would generate different IDs, breaking foreign keys
- Idempotence is handled by EF Core HasData matching on the `Id` primary key
- Store result as `{navigation_guid}`

## F4. Write Navigation Entity Seed

Based on `{level}`, write the seed entry.

**Option A: Project uses SeedData classes (SmartStack.app pattern)**

If `Navigation{Level}SeedData.cs` exists, add the new entity:

```csharp
// In Infrastructure/Persistence/Seeding/Data/Navigation/Navigation{Level}SeedData.cs

// Add static GUID field
public static readonly Guid {PascalCode}Id = Guid.Parse("{navigation_guid}");

// Add to GetSeedData() return array
new {
    Id = {PascalCode}Id,
    ParentFk = Navigation{ParentLevel}SeedData.{ParentPascalCode}Id,  // FK varies by level
    Code = "{code}",
    Label = "{labels.en}",
    Description = "{descriptions.en}",
    Icon = "{icon}",
    IconType = IconType.Lucide,
    Route = "/{full_path_with_slashes}",
    DisplayOrder = {display_order},
    IsActive = true,
    CreatedAt = SeedConstants.SeedDate
}
```

**FK property by level:**

| Level | FK Property | References |
|-------|-------------|------------|
| application | (none — top level) | — |
| module | `ApplicationId` | NavigationApplicationSeedData.{Parent}Id |
| section | `ModuleId` | NavigationModuleSeedData.{Parent}Id |

**Option B: Project uses inline HasData**

If no SeedData class exists, add directly to `Navigation{Level}Configuration.cs`:

```csharp
// In Configure method, add:
builder.HasData(new {
    Id = Guid.Parse("{navigation_guid}"),
    // ... same properties as Option A
});
```

## F5. Write Translation Entries

Add 4 translation entries to `NavigationTranslationConfiguration.cs`:

1. Read the file to find the current highest `index` value
2. Continue from `index + 1`
3. Use the SAME `GenerateGuid` method already defined in the file:

```csharp
// In GetSeedData() method, add at the end before return:

// {level}: {code} translations
translations.Add(new {
    Id = Guid.NewGuid(),
    EntityType = NavigationEntityType.{Level},
    EntityId = Navigation{Level}SeedData.{PascalCode}Id,  // or Guid.Parse("{navigation_guid}")
    LanguageCode = "fr",
    Label = "{labels.fr}",
    Description = "{descriptions.fr}",
    CreatedAt = seedDate
});
translations.Add(new {
    Id = Guid.NewGuid(),
    EntityType = NavigationEntityType.{Level},
    EntityId = Navigation{Level}SeedData.{PascalCode}Id,
    LanguageCode = "en",
    Label = "{labels.en}",
    Description = "{descriptions.en}",
    CreatedAt = seedDate
});
translations.Add(new {
    Id = Guid.NewGuid(),
    EntityType = NavigationEntityType.{Level},
    EntityId = Navigation{Level}SeedData.{PascalCode}Id,
    LanguageCode = "it",
    Label = "{labels.it}",
    Description = "{descriptions.it}",
    CreatedAt = seedDate
});
translations.Add(new {
    Id = Guid.NewGuid(),
    EntityType = NavigationEntityType.{Level},
    EntityId = Navigation{Level}SeedData.{PascalCode}Id,
    LanguageCode = "de",
    Label = "{labels.de}",
    Description = "{descriptions.de}",
    CreatedAt = seedDate
});
```

## F6. Store Result

```
{navigation_guid} = [generated GUID]
{seed_method} = "fallback"  // Indicates MCP was not used
```

## F7. Validation Checklist

Before proceeding, verify:
- [ ] Random GUID generated via Guid.NewGuid()
- [ ] 4 languages present (fr, en, it, de)
- [ ] No duplicate EntityType+EntityId+LanguageCode combinations
- [ ] Parent GUID correctly references existing entity
- [ ] Route path matches `/{app}/{module}` pattern
- [ ] DisplayOrder is consistent with existing entities
- [ ] Code is WRITTEN to files, not just displayed

## F8. Present Summary

```markdown
## Navigation Seeds Generated (Fallback)

**Entity:** {level} - {code}
**GUID:** {navigation_guid}
**Path:** {full_path}

### Files Updated

1. **Navigation{Level}SeedData.cs** (or Configuration.cs) - New entity entry
2. **NavigationTranslationConfiguration.cs** - 4 translation entries added
```
