---
name: review-model
description: Review a model definition (docs/models/<table-name>.md) using a structured 3-tier severity checklist.
argument-hint: "Relative path of the model document to review (e.g., docs/models/users.md)"
---

Read and review the contents of a target model (table definition) document in the workspace using a structured checklist with three severity levels (問題, 要確認, 提案).

## Review Checklist

### 1. 問題 (Issue/Problem - High Severity)

*Critical errors, logic flaws, or gaps that must be corrected.*

*   **構成要素の不足 (Missing Core Sections)**: Check if required sections are present: "モデル概要", "カラム定義", "インデックス定義", and "アソシエーション（関連）".
*   **キー定義の整合性 (PrimaryKey / ForeignKey Mismatch)**: Primary keys or foreign keys specified inカラム定義 that do not match the relationships defined in SCHEMA.md or standard naming rules.
*   **アソシエーションの論理矛盾 (Association Logic Error)**: Contradictory definitions in the relationships (e.g. table is defined as "belongs_to A" but A has no matching key or does not exist).
*   **スキーマ定義ルールへの非適応 (Violation of SCHEMA.md Rules)**: Column naming or index naming that violates rules specified in `docs/SCHEMA.md`.

### 2. 要確認 (Needs Confirmation/Clarification - Medium Severity)

*Items that require clarification or validation.*

*   **データ型と制約の妥当性 (Data Type & Constraints)**: Check if sizes (e.g. VARCHAR lengths) or constraints (Nullable vs NOT NULL, Default values) are reasonable for application logic.
*   **インデックス設計の妥当性 (Index Strategy)**: Missing indexes for foreign keys, or missing unique constraints for columns that should logically be unique (e.g., email address, identity code).

### 3. 提案 (Suggestion/Recommendation - Low Severity)

*Constructive ideas to improve clarity, aesthetics, or user experience.*

*   **カラム定義表の並び替え (Column Table Ordering)**: Grouping primary keys, foreign keys, logical data, and audit columns (e.g., `created_at`, `updated_at`) in a logical order.
*   **論理名/説明の充実 (Documentation Quality)**: Enhance descriptions for cryptic status codes or integer enums (e.g., `status: 0=Draft, 1=Published`).

---

## Execution Flow

1. **Locate Target File**:
   *   A file path argument is required. Prompt the user if not specified.
2. **Read Content**:
   *   Read the file content.
3. **Conduct Review**:
   *   Analyze the document line-by-line or section-by-section against the checklist.
4. **Save Report to File**:
   *   Save the formatted review report to `.review/[relative-path-to-target-document]` relative to the project root.
   *   Ensure the directories inside `.review/` are created automatically if they do not exist.
   *   If the report file already exists, overwrite it with the new review content.
5. **Output Report**:
   *   Present the structured review report in the chat and notify the user of the path to the saved file.

---

## Output Report Format

Output the review report using the following structure:

```markdown
# Document Review Report: [file basename]

Review of: `[relative/path/to/file]`

## Executive Summary

| Severity | Count | Key Focus |
| --- | --- | --- |
| 🔴 問題 (High) | 0 | Critical issues requiring immediate correction |
| 🟡 要確認 (Medium) | 0 | Items requiring user confirmation or alignment |
| 🟢 提案 (Low) | 0 | Suggestions for readability and quality |

---

## Detailed Findings

### 🔴 問題 (High Severity)
*List critical issues.*

- **[Short Summary of Issue]**
  - **Location**: Line X-Y / Section name
  - **Original Text**: `[original text]`
  - **Description**: [Why it is a problem]
  - **Recommended Action**: [Specific, actionable fix]

### 🟡 要確認 (Medium Severity)
*List items needing confirmation.*

- **[Short Summary]**
  - **Location**: Line X-Y / Section name
  - **Original Text**: `[original text]`
  - **Description**: [What needs confirmation and why]
  - **Recommended Action**: [Specific clarification questions or options]

### 🟢 提案 (Low Severity)
*List suggestions.*

- **[Short Summary]**
  - **Location**: Line X-Y / Section name
  - **Original Text**: `[original text]`
  - **Description**: [How it could be improved]
  - **Recommended Action**: [Concrete suggested text or structure]
```
