# Price Group Pricings

Contains pricing configurations and rules for price groups (both team-owned and operator-owned),
defining various charging tariffs, fees, and pricing structures. This model filters pricing data
to include only those associated with partner-specific price groups, enabling partner-customized
pricing management.

:::info{title="New model"}

This table is the replacement for the soon-to-be-deprecated [`team_price_group_pricings`](/docs/team_price_group_pricings). It includes pricings for both team-owned and operator-owned price groups.

:::

**SQL:** `price_group_pricings`

## Schema

| Column Name                   | Data Type     | Description                                                                                |
|:------------------------------|:--------------|:-------------------------------------------------------------------------------------------|
| **Primary ID**                |               |                                                                                            |
| id                            | INTEGER       | Primary key                                                                                |
| **Other IDs**                 |               |                                                                                            |
| price_group_id                | INTEGER       | Foreign key referencing the price group this pricing configuration belongs to               |
| team_id                       | INTEGER       | Foreign key referencing the team associated with this pricing configuration (null for operator-owned price groups) |
| operator_id                   | INTEGER       | Foreign key referencing the operator managing this price group                              |
| owner_id                      | INTEGER       | ID of the owner (team or operator) that owns the parent price group                         |
| owner_type                    | VARCHAR       | Type of owner — `Team` for team-owned price groups, `Operator` for operator-owned          |
| tariff_id                     | INTEGER       | Foreign key referencing the tariff structure associated with this pricing                  |
| tag_id                        | INTEGER       | Foreign key referencing tags used for categorizing or filtering this pricing configuration |
| **Timestamps**                |               |                                                                                            |
| created_at                    | TIMESTAMP_NTZ | Timestamp when the pricing configuration was initially created                             |
| updated_at                    | TIMESTAMP_NTZ | Timestamp when the pricing configuration was last modified                                 |
| deleted_at                    | TIMESTAMP_NTZ | Timestamp when the pricing configuration was soft deleted, null if still active            |
| from_timestamp                | TIMESTAMP_NTZ | Start timestamp when this pricing configuration becomes effective                          |
| to_timestamp                  | TIMESTAMP_NTZ | End timestamp when this pricing configuration expires, null for indefinite duration        |
| **Attributes**                |               |                                                                                            |
| type                          | VARCHAR       | Type of pricing configuration (tariff, fee, fixed_kwh, fixed_min, spot)                    |
| description                   | VARCHAR       | Human-readable description explaining the purpose and details of this pricing rule         |
| amount                        | NUMBER        | Base monetary amount for this pricing configuration, in the system's default currency      |
| vat                           | NUMBER        | Value-added tax rate applied to this pricing configuration, expressed as a decimal         |
| percentage                    | NUMBER        | Percentage-based pricing component, used for percentage-based fees or discounts            |
| start_min_after_charging      | INTEGER       | Number of minutes after charging begins when this pricing rule takes effect                |
| start_min_after_fully_charged | INTEGER       | Number of minutes after vehicle reaches full charge when this pricing rule activates       |
| end_at_fully_charged          | BOOLEAN       | Indicates whether this pricing rule automatically ends when the vehicle is fully charged   |
| amount_min                    | NUMBER        | Minimum monetary amount that can be charged under this pricing configuration               |
| amount_max                    | NUMBER        | Maximum monetary amount that can be charged under this pricing configuration               |
| interval                      | VARCHAR       | Time interval for recurring pricing applications, such as hourly or daily billing cycles   |
| master                        | BOOLEAN       | Indicates whether this is the master pricing configuration for the group                   |

## Inclusion Criteria
* the `price_group_id` must exist in the partner's `price_groups.id`

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

## Alignment
### Monta API
- Aligns with the pricing objects in the Monta API [get/price-groups](https://developer.monta.com/api/v1/price-groups/get) endpoint
- the `masterPrice` object requires that the `master = true`. There should be exactly 1 master price record per `price_group_id`
- the `fees` object - `where master = false and tariff_id is null`. There can be 0 to many fee records per `price_group_id`
- the `tariffs` object - `where master = false and tariff_id is not null`. There can be 0 to many tariff records per `price_group_id`

## Migration from `team_price_group_pricings`
This table replaces `team_price_group_pricings` and includes pricings for both team-owned and operator-owned price groups. The `team_price_group_pricings` table remains available during a transition period. Key differences:
- `team_price_group_id` is renamed to `price_group_id`
- Adds `owner_id`, `owner_type`, and `operator_id` columns
- `team_id` is null for operator-owned price groups

## Changes vs previous version

### Summary
- Adds `owner_id`, `owner_type`, and `operator_id` columns
- `team_price_group_id` is renamed to `price_group_id`
- Includes pricings for operator-owned price groups as new rows — filter on `owner_type = 'Team'` to get the same results as `team_price_group_pricings`

### Added columns (3)
- `owner_id` — ID of the owner (team or operator) that owns the parent price group
- `owner_type` — Type of owner (`Team` or `Operator`)
- `operator_id` — Foreign key referencing the operator managing this price group

### Removed columns (0)

### Renamed columns (1)
- `team_price_group_id` -> `price_group_id`

### New rows
Pricings for operator-owned price groups are now included. To replicate the old `team_price_group_pricings` results, filter on `owner_type = 'Team'`.
