# Data Model — Tenant UI Polish

This feature is read-only. It introduces no schema changes.

## Entities

### Tenant
- **Role**: scope boundary for all queries.
- **Source**: `Tenant::current()` (Filament tenancy).

### OperationRun
- **Role**: operations feed, KPIs, and canonical “View run” destinations.
- **Key fields used** (existing):
  - `tenant_id`
  - `type`
  - `status` (`queued|running|completed`)
  - `outcome` (`succeeded|partial|failed|...`)
  - `created_at`, `started_at`, `completed_at`
  - `summary_counts`, `failure_summary` (JSONB)

**Derived values**:
- **Active**: `status IN ('queued','running')`
- **Terminal**: `status = 'completed'`
- **Avg duration (7 days)**: only terminal runs with `started_at` and `completed_at`.

### InventoryItem
- **Role**: inventory totals and coverage chips.
- **Key fields used** (existing, inferred from resources):
  - `tenant_id`
  - coverage-related flags / fields used to categorize: Restorable, Partial, Risk, Dependencies

**Derived values**:
- Total items
- Coverage % = `restorable / total` (if total > 0)
- Chip counts: Restorable, Partial, Risk, Dependencies

### InventorySyncRun
- **Role**: “Last Inventory Sync” and “Sync Runs” list.
- **Key fields used**:
  - `tenant_id`
  - status + timestamps
  - any “selection_hash / selection payload” metadata used for display

### Finding (Drift Finding)
- **Role**: drift KPIs and “Needs Attention”.
- **Key fields used** (existing migration):
  - `tenant_id`
  - `severity` (enum-like string)
  - `status` (open/closed)
  - timestamps
  - `scope_key` for grouping

**Derived values**:
- Open findings by severity
- Staleness: last drift scan older than 7 days

## KPI Queries (read-only)

### Dashboard
- Drift KPIs: counts of open findings by severity + stale drift indicator.
- Operations health: counts of active runs + failed/partial recent.
- Recent lists: latest 10 findings + latest 10 operation runs.

### Inventory hub
- Total items
- Coverage % (restorable/total)
- Last inventory sync (status + timestamp)
- Active operations: (all active runs) + (inventory.sync active runs)

### Operations index
- Total runs (30d)
- Active runs (queued + running)
- Failed/partial (7d)
- Avg duration (7d, terminal runs only)

All queries must be tenant-scoped.
