# `Price`

An amount, and whether it includes tax.

Use it for what you charge. It stops a price with tax being taken for one without. For a plain amount, such as a refund or a balance, use [`Money`](/docs/types/type-money.md). For a price per kilo, use [`UnitPrice`](/docs/types/type-unit-price.md).

## Shape

| Field | Type | Required? |
|---|---|---|
| `amount` | [`Money`](/docs/types/type-money.md) | Yes |
| `includes_tax` | `Bool` | Yes |

## Example

```jadpo
Price { amount: money.from_minor(1050, Currency.gbp) includes_tax: true }
```

This operation gives one: `money.apply_discount`.

## Good to know

- The amount can't be below zero.
- `text.format` shows only the amount, `£10.50`. It doesn't say whether tax is included, so add that wording yourself.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it, so sort by one of its parts instead.

## In JSON

An object of its parts, in a request, a response or `json.write`:

```json
{"amount":{"amount":1050,"currency":"GBP"},"includes_tax":true}
{"amount":{"amount":875,"currency":"GBP"},"includes_tax":false}
{"amount":{"amount":1200,"currency":"EUR"},"includes_tax":true}
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`Price` is in the group Money and banking, and has been in Jadpo since 0.1.0.

### Text form

It has no single text form, so `text.from` and `text.parse` don't take it.

### How it is stored

It is stored in 3 columns, each named for the field, `_` and its suffix. This is `{"amount":{"amount":875,"currency":"GBP"},"includes_tax":false}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_amount` | `bigint` | `875` |
| `<field>_currency` | `char(3)` | `'GBP'` |
| `<field>_includes_tax` | `boolean` | `FALSE` |

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"amount":{"amount":1050,"currency":"GBP"},"includes_tax":true}` | `£10.50` |
| `{"amount":{"amount":875,"currency":"GBP"},"includes_tax":false}` | `£8.75` |
| `{"amount":{"amount":1200,"currency":"EUR"},"includes_tax":true}` | `€12.00` |

### Operations

- `money.apply_discount(price: Price, discount: Discount) -> Price`: `price` with `discount` taken off its amount, keeping whether it includes tax: an amount off in the price's currency, or that percentage of the amount, rounded half to even to a minor unit, so 15% off £10.05 is £1.51 off. More off than the price leaves nothing. It fails with `currency_mismatch` for an amount off in another currency.

It also takes `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
