# Reports

These reports capture issues, feedback, and incidents
related to charge points, charge, or operator, including user-submitted reports, system-generated alerts,
and support tickets from Zendesk.

**SQL:** `reports`
## Schema

| Column Name             | Data Type     | Description                                                                                                                               |
|:------------------------|:--------------|:------------------------------------------------------------------------------------------------------------------------------------------|
| **Primary ID**          |               |                                                                                                                                           |
| id                      | INTEGER       | Primary key - unique identifier for the report                                                                                            |
| **Other IDs**           |               |                                                                                                                                           |
| user_id                 | INTEGER       | ID of the user who created or is associated with the report                                                                               |
| relation_id             | INTEGER       | ID of the related entity based on the value of relation_type (either charge point id, charge id, or operator id)                          |
| operator_id             | INTEGER       | ID of the operator responsible for handling this report                                                                                   |
| assigned_to_operator_id | INTEGER       | ID of the operator to whom this report has been assigned                                                                                  |
| resolved_by_user_id     | INTEGER       | ID of the user who resolved this report                                                                                                   |
| assigned_to_user_id     | INTEGER       | ID of the specific user within the operator organization assigned to this report                                                          |
| reason_id               | INTEGER       | ID of the report reason/category (links to report_reasons table)                                                                          |
| **Timestamps**          |               |                                                                                                                                           |
| created_at              | TIMESTAMP_NTZ | Timestamp when the report was created in the system                                                                                       |
| updated_at              | TIMESTAMP_NTZ | Timestamp when the report was last updated                                                                                                |
| resolved_at             | TIMESTAMP_NTZ | Timestamp when the report was marked as resolved                                                                                          |
| escalated_at            | TIMESTAMP_NTZ | Timestamp when the report was escalated to a higher priority or different team                                                            |
| assigned_at             | TIMESTAMP_NTZ | Timestamp when the report was assigned to an operator or user                                                                             |
| deleted_at              | TIMESTAMP_NTZ | Timestamp when the report was soft-deleted (null if not deleted)                                                                          |
| **Attributes**          |               |                                                                                                                                           |
| relation_type           | VARCHAR       | Type of entity the report relates to ('charge_point' (most often), 'charge', or 'operator')                                               |
| body                    | VARCHAR       | Main content/description of the report provided by the user or system                                                                     |
| admin_note              | VARCHAR       | Internal note added by Monta administrators (not visible to operators)                                                                    |
| operator_note           | VARCHAR       | Note added by the operator handling the report                                                                                            |
| user_note               | VARCHAR       | Additional note or comment from the user who created the report                                                                           |
| image1_path             | VARCHAR       | File path or URL to the first attached image (if any)                                                                                     |
| image2_path             | VARCHAR       | File path or URL to the second attached image (if any)                                                                                    |
| image3_path             | VARCHAR       | File path or URL to the third attached image (if any)                                                                                     |
| state                   | VARCHAR       | Current state of the report (e.g., 'new', 'assigned_operator', 'assigned_monta', 'escalated_installer', 'escalated_hardware', 'resolved') |
| source                  | VARCHAR       | Origin of the report (e.g., 'app', 'system', 'zendesk', 'web') indicating how the report was created                                      |
| log                     | VARIANT       | JSON array containing historical log entries tracking state changes, assignments, and other events in the report lifecycle                |

## Inclusion Criteria
* the `operator_id` or `assigned_operator_id` must exist in the operator's `operators.id` values

## Data flow
| Upstream tables     | Downstream tables |
|:--------------------|:------------------|
| `operators` | None              |

## Alignment
### Monta API
- Aligns with the pricing objects in the Monta API [get/reports](https://developer.monta.com/api/v1/reports) endpoint
