# Document Types — Design Spec

Date: 2026-03-23
Status: Approved

## Goal

Add a `type` field to documents so users can classify them (documentation, devis, facture, plan, photo, autre). Users can set the type at upload and change it afterward via a mini-modal.

## Enum Values

| Value | Label |
|-------|-------|
| `documentation` | Documentation |
| `devis` | Devis |
| `facture` | Facture |
| `plan` | Plan |
| `photo` | Photo |
| `autre` | Autre |

Default: `documentation`

## Backend

### 1. PHP Enum

New file: `src/Enum/DocumentType.php`

```php
enum DocumentType: string
{
    case DOCUMENTATION = 'documentation';
    case DEVIS = 'devis';
    case FACTURE = 'facture';
    case PLAN = 'plan';
    case PHOTO = 'photo';
    case AUTRE = 'autre';
}
```

### 2. Entity Change — Document.php

Add column:

```php
#[ORM\Column(type: Types::STRING, length: 20, enumType: DocumentType::class)]
#[Groups(['document:list'])]
private DocumentType $type = DocumentType::DOCUMENTATION;
```

Add getter/setter:

```php
public function getType(): DocumentType { ... }
public function setType(DocumentType $type): static { ... }
```

### 3. API Platform — PATCH operation

Add a `Patch` operation on Document (ROLE_GESTIONNAIRE) to allow updating `name` and `type`. The existing `Put` already exists but PATCH is more appropriate for partial updates.

### 4. DocumentUploadProcessor

Accept optional `type` field from FormData. Validate against enum values, default to `documentation` if absent.

### 5. Migration

```sql
ALTER TABLE documents ADD COLUMN type VARCHAR(20) NOT NULL DEFAULT 'documentation';

-- Classify existing documents by mimeType
UPDATE documents SET type = 'photo' WHERE mimetype LIKE 'image/%';
UPDATE documents SET type = 'autre'
  WHERE type = 'documentation'
    AND mimetype NOT LIKE 'application/pdf'
    AND mimetype NOT LIKE 'image/%';
```

### 6. DocumentQueryController

Add `type` to the response array in `formatDocument()`.

## Frontend

### 1. Type Constants

New file: `app/shared/documentTypes.ts`

```typescript
export const DOCUMENT_TYPES = [
  { value: 'documentation', label: 'Documentation' },
  { value: 'devis', label: 'Devis' },
  { value: 'facture', label: 'Facture' },
  { value: 'plan', label: 'Plan' },
  { value: 'photo', label: 'Photo' },
  { value: 'autre', label: 'Autre' },
] as const

export type DocumentTypeValue = typeof DOCUMENT_TYPES[number]['value']
```

### 2. DocumentUpload.vue — Type select at upload

Add a select dropdown (default: `documentation`) in the upload zone. The selected type applies to all files in the current batch. Pass the type through to `uploadDocuments()`.

### 3. useDocuments composable

- `uploadDocuments()`: accept `type` in the upload context, append to FormData
- New method: `updateDocument(id, { name, type })` — PATCH `/api/documents/{id}` with `application/merge-patch+json`
- Add `type` to the `Document` interface

### 4. DocumentEditModal.vue (new component)

Mini-modal with:
- Input text: document name (pre-filled)
- Select: document type (pre-filled)
- Buttons: Annuler / Sauvegarder
- On save: call `updateDocument()`, emit `updated` event

### 5. Document list display

Everywhere documents are listed (machine detail, composant edit, piece edit, product, site):
- Show type as a small badge next to the document name
- Add a pencil/edit button that opens `DocumentEditModal`
- On modal save: refresh the document in local state

## Migration of existing data

All existing documents classified by mimeType:
- `image/*` → `photo`
- `application/pdf` → `documentation`
- Everything else → `autre`

## Out of scope

- Custom user-defined types (table `document_types`) — can be added later
- Filtering documents by type in the UI — can be added later
- Bulk type change
