# TaskManager

## Summary

A complete personal task management system supporting creation, completion, and deletion of daily todos.

## Requirements

- Users can create new tasks with a title and optional description.
- Users can mark active tasks as completed.
- Users can delete tasks to remove them permanently.
- Tasks must securely belong only to the authenticated user.

## Tests

- A user cannot view or complete a task owned by a different user.
- Completing an already completed task returns safely without error.

## Record: TodoItem

### Summary

The core data entity representing a single user task.

### Schema

```schema
id: string generated unique
ownerId: string required
title: string required max(100)
description: string optional
status: enum(PENDING, COMPLETED) required default(PENDING)
createdAt: timestamp generated
```

## Contract: CreateTodo

### Summary

Creates a new pending task for the active user.

### Input

```schema
title: string required
description: string optional
```

### Authz

- User must be actively authenticated.

### Expects

- Title must not be empty or purely whitespace.

### Ensures

- Orchestration is delegated to the creation flow — [invokes](aim:#Flow:ExecuteCreateTodo).
- Persists a new TodoItem with `status="PENDING"` and `ownerId=currentUser.id` — [mutates](aim:#Record:TodoItem).
- Emits the creation event — [emits](aim:#Event:TodoCreated).

### Returns

- The created TodoItem.

## Contract: CompleteTodo

### Summary

Safely marks an active task as complete.

### Input

```schema
todoId: string required
```

### Authz

- User must be authenticated.
- User must be the `ownerId` of the TodoItem.

### Expects

- The TodoItem record must exist.
- `TodoItem.status` must currently be `PENDING`.

### Ensures

- Updates `TodoItem.status` to `COMPLETED` — [mutates](aim:#Record:TodoItem).

### Returns

- The updated TodoItem.

## Flow: ExecuteCreateTodo

### Summary

Orchestrates database insertion and event publishing for new tasks.

### Steps

1. Extract the userId via `Auth.GetCurrentUser`.
2. Construct a new TodoItem with input data and the extracted userId.
3. Insert the record — [mutates](aim:#Record:TodoItem).
4. Publish the creation event — [emits](aim:#Event:TodoCreated).

### On Error

- Log a warning via `Logger.Warn("Failed to create task")`.
- Rethrow the error to surface to the UI.

## Persona: StandardUser

A regular individual managing their personal task list.

### Role

- `user:standard`

### Access

- [accesses](aim:#View:TodoDashboard)

## View: TodoDashboard

### Summary

The main interface for viewing and interacting with the task list.

### Display

- A list of [reads](aim:#Record:TodoItem) records where `ownerId = currentUser.id`.
- Visual distinction between PENDING and COMPLETED tasks.
- Empty state message if no tasks exist.

### Actions

- Submitting the "New Task" form — [exposes](aim:#Contract:CreateTodo)
- Tapping the checkbox on a PENDING task — [exposes](aim:#Contract:CompleteTodo)

### Layout

- The "New Task" form sits above the list.
- Completed tasks below the pending ones.

## Style: Plain

### Summary

Quiet and legible: a white sheet, dark text, one blue for the action — nothing decorative.

### Palette

- surface: white
- ink: near-black `#1f1f1f`
- accent: one clear blue for the primary action

### Type

- body: the platform's own sans, comfortable size

### Shape

- corners: slightly rounded
- elevation: flat

## State: TodoStatus

### Summary

A todo is pending until its owner completes it; a completed todo stays completed.

### Of

- `Record:TodoItem.status`

### States

- Pending — initial
- Completed — final

### Moves

- Pending → Completed — [Contract:CompleteTodo]

## Event: TodoCreated

### Summary

Emitted when a new todo is persisted.

### Payload

```schema
todoId: string required
ownerId: string required
createdAt: timestamp required
```

### Routing

- Channel: `todos.created`
