# Story 1.4: Gestion des Types & Renommage (Data Hygiene)

Status: review

## Story

As a Julien (Analyst),
I want to rename columns and correct data types,
so that the data matches my business context before analysis.

## Acceptance Criteria

1. **Column Renaming:** Users can click a column header to rename it. Changes are reflected instantly in the grid.
2. **Type Override:** Users can change the data type of a column (e.g., String -> Numeric). 
3. **Backend Sync:** Type changes are sent to the backend to validate if the data can be cast correctly.
4. **Visual Feedback:** Column headers display the current data type (e.g., "Num", "Cat").
5. **State Persistence:** Column names and types are preserved in the Zustand store.

## Tasks / Subtasks

- [x] **Frontend Header UI** (AC: 1, 4)
  - [x] Implement editable column header in `src/features/smart-grid/components/SmartGrid.tsx`.
  - [x] Add type indicator badges to headers.
- [x] **Type Management Logic** (AC: 2, 5)
  - [x] Update `useGridStore` to support `updateColumn` action (rename, change type).
- [x] **Backend Validation** (AC: 3)
  - [x] Add endpoint `/api/v1/analysis/validate-type` to verify casting feasibility.
  - [x] Handle casting errors gracefully.

## Dev Notes

- **Performance:** Local renames handle data key updates in-memory to avoid full dataset re-ingestion.
- **UI:** Implemented inline editing for headers with immediate visual feedback.
- **Backend:** Added Pydantic model for type validation requests.

### Project Structure Notes

- Modified `frontend/src/store/use-grid-store.ts` to add mutation logic.
- Created `backend/app/api/v1/analysis.py` for validation logic.
- Updated `frontend/src/features/smart-grid/components/SmartGrid.tsx` with `EditableHeader`.

### References

- [Source: epics.md#Story 1.4]
- [Source: project-context.md#Data & State Architecture]

## Dev Agent Record

### Agent Model Used

{{agent_model_name_version}}

### Completion Notes List
- Implemented inline column renaming in the grid.
- Added a dropdown for data type override (Num, Cat, Date, Bool).
- Developed a FastAPI endpoint for validating data type conversions.
- Optimized Zustand store to update data keys when a column is renamed.

### File List
- /frontend/src/store/use-grid-store.ts
- /backend/app/api/v1/analysis.py
- /backend/main.py
- /frontend/src/features/smart-grid/components/SmartGrid.tsx