# /workflow - Gestion Workflows SmartStack

> **Synergie Skill/Commande:**
> - **Skill** (`templates/skills/workflow/`) → Invocation automatique par Claude
> - **Commande** (`/workflow`) → Invocation manuelle par l'utilisateur

---

## ARGUMENTS

```
/workflow <action> [options]
```

| Action | Description |
|--------|-------------|
| `create` | Creer un nouveau workflow complet |
| `trigger` | Ajouter un nouveau trigger |
| `step` | Ajouter un step a un workflow existant |
| `template` | Creer un email template |

---

## WORKFLOW

### /workflow create

Cree un workflow complet avec trigger et steps.

**Questions:**
1. Code du workflow ? (kebab-case)
2. Nom descriptif ?
3. Quel trigger ? (existant ou nouveau)
4. Quels steps ? (Email, Wait, Condition, Webhook)
5. Systeme ? (oui/non)
6. Priorite ? (1-100, defaut 10)

**Actions:**
1. Creer/utiliser le trigger
2. Ajouter le workflow dans WorkflowConfiguration.cs seed
3. Ajouter les steps dans WorkflowStepConfiguration.cs seed
4. Creer les email templates si necessaire
5. Creer migration EF Core

### /workflow trigger

Ajoute un nouveau trigger.

**Questions:**
1. Code du trigger ? (format: entity.event)
2. Nom descriptif ?
3. Variables disponibles ?

**Actions:**
1. Ajouter dans WorkflowTriggerConfiguration.cs seed
2. Creer migration EF Core

### /workflow step

Ajoute un step a un workflow existant.

**Questions:**
1. Quel workflow ?
2. Type de step ? (SendEmail, Wait, Condition, Webhook)
3. Configuration specifique selon le type

**Actions:**
1. Ajouter dans WorkflowStepConfiguration.cs seed
2. Mettre a jour l'ordre des steps
3. Creer migration EF Core

### /workflow template

Cree un email template.

**Questions:**
1. Code du template ?
2. Nom ?
3. Categorie ? (Transactional, Marketing, System)
4. Langues ? (fr, en, it, de)

**Actions:**
1. Ajouter dans EmailTemplateConfiguration.cs seed
2. Ajouter les translations
3. Creer migration EF Core

---

## TEMPLATES

### Template Trigger Seed

```csharp
new
{
    Id = Guid.Parse("$TRIGGER_GUID"),
    Code = "$ENTITY.$EVENT",
    Name = "$NAME",
    Description = "$DESCRIPTION",
    TriggerType = "$TRIGGER_TYPE",
    AvailableVariablesJson = JsonSerializer.Serialize(new[]
    {
        new { Name = "entityId", Type = "Guid", Description = "Entity ID" },
        new { Name = "entityName", Type = "string", Description = "Entity name" },
        new { Name = "userEmail", Type = "string", Description = "User email" },
    }),
    IsActive = true,
    CreatedAt = seedDate
},
```

### Template Workflow Seed

```csharp
new
{
    Id = Guid.Parse("$WORKFLOW_GUID"),
    Code = "$CODE",
    Name = "$NAME",
    Description = "$DESCRIPTION",
    TriggerId = Guid.Parse("$TRIGGER_GUID"),
    ApplicationId = (Guid?)null,
    IsActive = true,
    IsSystem = $IS_SYSTEM,
    Priority = $PRIORITY,
    CreatedAt = seedDate
},
```

### Template Step Seed (Email)

```csharp
new
{
    Id = Guid.Parse("$STEP_GUID"),
    WorkflowId = Guid.Parse("$WORKFLOW_GUID"),
    Name = "$NAME",
    StepType = WorkflowStepType.SendEmail,
    StepOrder = $ORDER,
    EmailTemplateId = Guid.Parse("$TEMPLATE_GUID"),
    IsActive = true,
    CreatedAt = seedDate
},
```

### Template Step Seed (Wait)

```csharp
new
{
    Id = Guid.Parse("$STEP_GUID"),
    WorkflowId = Guid.Parse("$WORKFLOW_GUID"),
    Name = "$NAME",
    StepType = WorkflowStepType.Wait,
    StepOrder = $ORDER,
    DelayMinutes = $DELAY_MINUTES,
    IsActive = true,
    CreatedAt = seedDate
},
```

### Template Declenchement

```csharp
await _workflowService.TriggerAsync(
    "$TRIGGER_CODE",
    new Dictionary<string, object>
    {
        ["entityId"] = entity.Id,
        ["entityName"] = entity.Name,
        ["userEmail"] = _currentUser.Email
    },
    language: "fr",
    cancellationToken: ct);
```

---

## FICHIERS CLES

| Fichier | Role |
|---------|------|
| `Domain/Communications/Workflow.cs` | Entite workflow |
| `Domain/Communications/WorkflowStep.cs` | Entite step |
| `Domain/Communications/WorkflowTrigger.cs` | Entite trigger |
| `Infrastructure/.../WorkflowConfiguration.cs` | Seed workflows |
| `Infrastructure/.../WorkflowTriggerConfiguration.cs` | Seed triggers |
| `Infrastructure/.../WorkflowStepConfiguration.cs` | Seed steps |
| `Infrastructure/Services/Workflow/WorkflowExecutionService.cs` | Execution |

---

User: $ARGUMENTS
