# Team Members

Contains team membership data including member permissions, invitation workflows,  and payment configurations. Enriched with team metadata to provide comprehensive  member management capabilities for partner organizations.

**SQL:** `team_members`

## Schema

| Column Name                              | Data Type     | Description                                                                  |
|:-----------------------------------------|:--------------|:-----------------------------------------------------------------------------|
| **Primary ID**                           |               |                                                                              |
| id                                       | INTEGER       | Primary key                                                                  |
| **Other IDs**                            |               |                                                                              |
| team_id                                  | INTEGER       | References the team that this membership belongs to                          |
| user_id                                  | INTEGER       | References the user who is a member of the team                              |
| nested_team_id                           | INTEGER       | References a nested or sub-team within the organizational hierarchy          |
| accepted_by_user_id                      | INTEGER       | References the user who accepted this team membership invitation             |
| blocked_by_user_id                       | INTEGER       | References the user who blocked this team membership                         |
| invited_by_user_id                       | INTEGER       | References the user who sent the team membership invitation                  |
| member_fee_id                            | INTEGER       | References the fee structure associated with this membership                 |
| price_group_id                           | INTEGER       | References the pricing group that applies to this member                     |
| partner_external_id                      | VARCHAR       | External identifier used by the partner system for this membership           |
| partner_external_team_id                 | VARCHAR       | External team identifier used by the partner system                          |
| **Timestamps**                           |               |                                                                              |
| created_at                               | TIMESTAMP_NTZ | Timestamp when the team membership record was created                        |
| updated_at                               | TIMESTAMP_NTZ | Timestamp when the team membership record was last modified                  |
| deleted_at                               | TIMESTAMP_NTZ | Timestamp when the team membership was soft deleted, null if active          |
| invited_at                               | TIMESTAMP_NTZ | Timestamp when the team membership invitation was sent                       |
| requested_at                             | TIMESTAMP_NTZ | Timestamp when the team membership was requested by the user                 |
| expires_at                               | TIMESTAMP_NTZ | Timestamp when the team membership invitation expires                        |
| accepted_at                              | TIMESTAMP_NTZ | Timestamp when the team membership invitation was accepted                   |
| rejected_at                              | TIMESTAMP_NTZ | Timestamp when the team membership invitation was rejected                   |
| blocked_at                               | TIMESTAMP_NTZ | Timestamp when the team membership was blocked                               |
| next_member_fee_purchase_at              | TIMESTAMP_NTZ | Scheduled timestamp for the next member fee payment                          |
| **Filters**                              |               |                                                                              |
| is_viewed                                | BOOLEAN       | Indicates whether the team membership has been viewed by the recipient       |
| is_main_operator_match                   | BOOLEAN       | Indicates whether the team matches the main operator criteria                |
| is_parent_operator_match                 | BOOLEAN       | Indicates whether the team matches the parent operator criteria              |
| is_deleted_pii                           | BOOLEAN       | Indicates whether the row was deleted and needs PII overwritten              |
| **Attributes**                           |               |                                                                              |
| access                                   | VARCHAR       | Access level granted to the team member                                      |
| can_configure_charge_points              | BOOLEAN       | Indicates whether the member can configure charging station settings         |
| can_use_for_manage_wallet                | BOOLEAN       | Indicates whether the member can manage wallet functionality                 |
| can_use_for_payments                     | BOOLEAN       | Indicates whether the member can process payments                            |
| can_use_for_payments_charges             | BOOLEAN       | Indicates whether the member can handle payment charges                      |
| can_use_for_payments_charges_country_ids | VARCHAR       | Comma-separated list of country IDs where member can process payment charges |
| can_deposit_to_wallet                    | BOOLEAN       | Indicates whether the member can deposit funds to the team wallet            |
| can_withdraw_from_wallet                 | BOOLEAN       | Indicates whether the member can withdraw funds from the team wallet         |
| can_request_sponsoring                   | BOOLEAN       | Indicates whether the member can request charge sponsoring                   |
| can_manage_members                       | BOOLEAN       | Indicates whether the member can manage other team members                   |
| member_fee_purchases_count               | INTEGER       | Total number of member fee purchases made by this member                     |
| note                                     | VARCHAR       | Additional notes or comments about the team membership                       |
| role                                     | VARCHAR       | Role assigned to the team member within the organization                     |
| state                                    | VARCHAR       | Current state of the team membership (pending, active, blocked, etc.)        |
| cost_group_id                            | INTEGER       | References the cost group associated with this member                        |
| team_member_profile_id                   | INTEGER       | References the team member profile record                                    |
| email                                    | VARCHAR       | Email address of the team member                                             |
| phone                                    | VARCHAR       | Phone number of the team member                                              |
| invited_by                               | VARCHAR       | Name or identifier of the person who sent the invitation                     |
| accepted_by                              | VARCHAR       | Name or identifier of the person who accepted the invitation                 |
| new_user                                 | BOOLEAN       | Indicates whether this is a newly registered user joining the team           |

## Data inclusion criteria
This table works with `operator_id` or `parent_operator_id`must match the operator's ID.

## Data flow 
| Upstream tables | Downstream tables |
|:----------------|:------------------|
| ---             | ---               |

## Alignment
### Monta API
- Aligns with Monta API [get/team-members](https://developer.monta.com/api/v1/team-members/get) endpoint 
- the API only includes non-deleted rows that have non-missing uder_id and that match on the main operator id, not sub-operators 

```sql
where deleted_at is null and is_main_operator_match = true and user_id is not null
```
