# `IdentityDocument`

An identity document: its kind, the country, its number and when it expires.

Use it for identity checks that accept several kinds of document. When you take only one kind, [`PassportNumber`](/docs/types/type-passport-number.md) or [`DrivingLicenceNumber`](/docs/types/type-driving-licence-number.md) says so.

## Shape

| Field | Type | Required? |
|---|---|---|
| `kind` | [`IdentityDocumentKind`](/docs/types/type-identity-document-kind.md) | Yes |
| `country` | [`Country`](/docs/types/type-country.md) | Yes |
| `number` | `Text` | Yes |
| `expires` | [`CalendarDate`](/docs/types/type-calendar-date.md) | No |

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

Its parts keep these rules, and a value that breaks one fails with the rule's name:

- `number_of_kind_and_country`: number is in the form of its kind of document from its country

## Example

```jadpo
IdentityDocument {
    kind: IdentityDocumentKind.passport
    country: Country.gb
    number: "123456789"
    expires: "2031-05-01"
}
```

## Good to know

- The number is checked against the form for that kind from that country.
- Give `expires: none` for a document with no expiry date.
- `text.format` shows only the last four characters.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it, so sort by one of its parts instead.
- A field that holds one counts as personal data (`government_id`), so you don't mark it yourself.

## In JSON

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

```json
{"kind":"passport","country":"GB","number":"123456789","expires":"2030-01-31"}
{"kind":"identity_card","country":"DE","number":"L01X00T47","expires":null}
```

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>

`IdentityDocument` is in the group Tax and identity numbers, 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 4 columns, each named for the field, `_` and its suffix. This is `{"kind":"identity_card","country":"DE","number":"L01X00T47","expires":null}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_kind` | `text` | `'identity_card'` |
| `<field>_country` | `text` | `'DE'` |
| `<field>_number` | `text` | `'L01X00T47'` |
| `<field>_expires` | `date` | `NULL::date` |

### How it is shown to people

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

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"kind":"passport","country":"GB","number":"123456789","expires":"2030-01-31"}` | `•••• 6789` |
| `{"kind":"identity_card","country":"DE","number":"L01X00T47","expires":null}` | `•••• 0T47` |

### Operations

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>
