# `IdentityDocument`

An identity document: its kind, the country that issued it, its number in that country's form for its kind, and the day it expires, if it does. Shown as its number masked to its last four. Personal data.

[Tax and identity numbers](types.md#tax-and-identity-numbers); not ordered; since Jadpo 0.1.0.

## Make one

Build one from its fields, `IdentityDocument { kind: ...  country: ...  number: ... }`.

Its parts keep these rules; 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`

## Fields

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

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an object of its parts.

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

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` |

## 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 has the contract's own operations: `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
