# `FlightNumber`

A flight's code: `BA123`.

Use it for a passenger's flight. For the airline alone, use [`IataAirline`](/docs/types/type-iata-airline.md).

## Shape

| Field | Type | Required? |
|---|---|---|
| `airline` | [`IataAirline`](/docs/types/type-iata-airline.md) | Yes |
| `number` | `Int` | Yes |
| `suffix` | `Text` | No |

Write every field when you build one, and give a field that isn't required as `none`.

## Example

```jadpo
FlightNumber { airline: "BA" number: 123 suffix: none }
```

`text.parse(raw, as: FlightNumber)` reads one from text that comes from outside. Text that isn't one at all fails `malformed`, such as `BA0123`, `BA 123` or `ba123`.

## Good to know

- The number runs from 1 to 9999, and it has no leading zeros, so `BA0123` is refused.
- `==` 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

A string, in a request, a response or `json.write`:

```json
"BA123"
"U21234"
"6E2001"
```

When you read one, a field that isn't required may be left out, or sent as `null`.

## Details

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

`FlightNumber` is in the group Travel, and has been in Jadpo since 0.1.0.

### Text form

`text.from` writes one standard text form, the same form `text.parse` reads back: `BA123`, `U21234` and `6E2001`.

### How it is stored

It is stored in 3 columns, each named for the field, `_` and its suffix. This is `6E2001`:

| Column | Type | Holds |
|---|---|---|
| `<field>_airline` | `text` | `'6E'` |
| `<field>_number` | `integer` | `2001` |
| `<field>_suffix` | `text` | `NULL::text` |

### How it is shown to people

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

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `BA123` | `BA123` |
| `U21234` | `U21234` |
| `6E2001` | `6E2001` |
| `BA5A` | `BA5A` |

### Operations

It also takes `text.parse`, `text.from`, `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>
