# Support Cases

## Overview

This journey covers how customers create and manage support tickets through the portal. Cases are stored in Salesforce as Case records with the origin "Portal Support." Customers can create new cases, view their case list with filters, read the full conversation history for each case, and add replies. The portal shows only customer-friendly statuses (New, In Progress, Awaiting Customer, Closed) -- internal Salesforce workflow statuses are hidden.

## Portal Flow

### Viewing the Support Cases List

1. Navigate to **Account > Support** (URL: `/account/support`).
2. The page loads with the title "Support Cases" and the subtitle "Track and manage your support requests."
3. A **New Case** button appears in the top-right corner.
4. At the top, **summary statistics** show:
   - **Total** cases
   - **Open** cases (cases that are not Closed)
   - **High Priority** (shown only when count is greater than zero)
   - **Resolved** (Closed cases)
5. Below the stats, a **search and filter bar** provides:
   - **Search** by case number or subject (free-text)
   - **Filter by status**: All Statuses, New, In Progress, Awaiting Customer, Closed
   - **Filter by priority**: All Priorities, Low, Medium, High
   - A **Clear Filters** button when any filter is active
6. Each case in the list shows:
   - A status icon (colored by status)
   - The **case number** (e.g., #00001234) and **subject**
   - A **status badge** (color-coded) and **priority badge** (color-coded)
   - The **category** if one was assigned
   - A **last updated** timestamp (relative, e.g., "2 hours ago")
7. Clicking a case row navigates to the case detail page.
8. If no cases exist, an empty state message reads "No support cases found" with a prompt to create one.

### Creating a New Support Case

1. Click the **New Case** button or navigate to `/account/support/new`.
2. The page shows:
   - An **AI Assistant suggestion** banner at the top suggesting the customer try the AI chat first for instant answers.
   - A form with three fields:
     - **Subject** (required): Brief description of the issue. Maximum 255 characters.
     - **Priority** (optional, defaults to Medium): A dropdown with three options:
       - Low -- General question
       - Medium -- Issue affecting work
       - High -- Urgent / Service disruption
     - **Description** (required): Detailed description of the issue. The helper text reads: "The more details you provide, the faster we can help you."
3. Click **Create Case** to submit.
4. On success, the customer is redirected to the support cases list with a success indicator.
5. At the bottom, a **contact options** section shows:
   - **Phone Support**: 0120-660-470 (Mon-Fri, 9:30-18:00 JST)
   - **AI Chat Assistant**: Available 24/7

### Viewing a Case Detail

1. From the case list, click a case to open its detail page (URL: `/account/support/{caseId}`).
2. The page header shows:
   - The case subject and case number
   - **Status badge** (New, In Progress, Awaiting Customer, or Closed)
   - **Priority badge** (Low, Medium, or High)
   - **Created** date and **Updated** timestamp
   - **Category** if one was assigned
   - **Closed** date if the case is closed
3. Below the header, the **Conversation** section shows all messages in a chat-like format:
   - The customer's original description appears as the first message.
   - **Messages are grouped by date** with separators (Today, Yesterday, or the specific date like "Mon, Dec 30").
   - **Customer messages** appear on the right side with a colored bubble.
   - **Support team messages** appear on the left side.
   - Each message shows the author name, timestamp, and whether it came via email or as a comment.
   - Messages with **attachments** show a paperclip icon.
   - **New messages** (since the customer last viewed the case) show a "New" badge.
   - Consecutive messages from the same person within 5 minutes are grouped together for a cleaner look.
4. A **Refresh** button at the top of the conversation allows manually refreshing messages. Messages also auto-refresh every 30 seconds.

### Adding a Reply to a Case

1. At the bottom of the case detail page, a **reply form** appears (for open cases only).
2. Type a message in the text area and click **Send Reply**.
3. The message appears immediately in the conversation (optimistic update) with a "Sending..." indicator.
4. Once confirmed, a brief "Sent" confirmation appears.
5. If sending fails, the message text is restored to the input field so the customer can try again.
6. **Closed cases**: The reply form is replaced with a notice: "This case is closed. If you need further assistance, please create a new case."

### Status Meanings

The portal simplifies Salesforce's internal statuses into four customer-friendly values:

| Portal Status     | What It Means                                  |
| ----------------- | ---------------------------------------------- |
| New               | Case was just created, not yet reviewed        |
| In Progress       | Support team is working on it                  |
| Awaiting Customer | Support has replied, waiting for your response |
| Closed            | Case is resolved and closed                    |

### Priority Meanings

| Priority | Color | When to Use                        |
| -------- | ----- | ---------------------------------- |
| Low      | Green | General questions, no urgency      |
| Medium   | Amber | Issue affecting your work          |
| High     | Red   | Urgent issue or service disruption |

## What Happens in Salesforce

- **Case creation**: A new Case record is always created in Salesforce (never updates an existing one). Find it under **Cases** in Salesforce, filtered by Origin = "Portal Support."
- **Key fields to check on the Case**:

  | Field       | API Name         | Expected Value                                                     |
  | ----------- | ---------------- | ------------------------------------------------------------------ |
  | Subject     | `Subject`        | Matches what the customer entered                                  |
  | Description | `Description`    | Matches the customer's description                                 |
  | Status      | `Status`         | "新規" (New) -- initial status                                     |
  | Priority    | `Priority`       | "低" (Low), "中" (Medium), or "高" (High)                          |
  | Origin      | `Origin`         | "Portal Support" (customer-visible cases)                          |
  | Type        | `Type`           | Category selected: Technical, Billing, General, or Feature Request |
  | Account     | `AccountId`      | The customer's Salesforce Account ID                               |
  | Contact     | `ContactId`      | The customer's Salesforce Contact ID                               |
  | Opportunity | `Opportunity__c` | Linked Opportunity (if case relates to a specific service)         |

- **Case comments**: When the customer adds a reply, a **CaseComment** record is created on the Case. Check under the Case's "Case Comments" related list.
- **Email messages**: If support replies via email, an **EmailMessage** record is attached to the Case. These appear in the portal conversation alongside comments.
- **Status changes**: When an agent changes the Case status in Salesforce, the portal automatically picks up the change. A Platform Event (`Case_Status_Update__e`) is fired, which clears the portal's cache and sends a real-time update.
- **Categories**: Map to the Salesforce Case **Type** field. Possible values: Technical, Billing, General, Feature Request.

## Key Things to Verify

- **Case creation**: Create a new case and verify it appears in Salesforce with the correct Subject, Description, Priority, Status (New), and Origin ("Portal Support").
- **Case list accuracy**: The list matches the cases shown in Salesforce for the customer's Account. Status and priority badges show correctly.
- **Filtering**: Filter by status (e.g., "In Progress") and verify only matching cases appear. Search by case number returns the correct case.
- **Conversation timeline**: The case detail shows the description as the first message, followed by all CaseComments and EmailMessages in chronological order. Messages are grouped by date correctly.
- **Adding a reply**: Post a reply and verify a CaseComment record is created in Salesforce on the Case. The comment body matches what was typed.
- **Real-time status updates**: Change the Case status in Salesforce (e.g., from New to In Progress). The portal should reflect the change shortly without a manual page refresh.
- **Closed case behavior**: When a case has status Closed in Salesforce, the reply form in the portal is hidden and replaced with a "case is closed" notice.
- **Status mapping**: Verify that internal Salesforce statuses are correctly simplified. For example, a Case with status "Awaiting Approval" or "VPN Pending" in Salesforce should show as "In Progress" in the portal.
- **Error handling**: If Salesforce is unavailable, the portal shows "support system unavailable, please try again later" rather than broken data.
- **Case not found**: Trying to access a case ID that belongs to another customer shows "Case not found" without leaking information.
