# DZ Phone Normalization

## Canonical storage

This project stores Algerian mobile numbers in canonical E.164 format without the plus sign:

- Example input: `0665303336`
- Stored canonical value: `213665303336`

The canonical operational field is `phone_e164`.

For backward compatibility, new writes also synchronize legacy phone fields such as `phone`, `secondary_phone`, `phone1`, and `phone2` to the same normalized `213...` value.

## UI display

Human-facing screens should display Algerian numbers in local format when possible:

- Stored canonical value: `213665303336`
- Displayed UI value: `0665303336`

If a legacy value cannot be normalized safely, the UI falls back to the original stored value instead of showing an empty phone field.

## Accepted input formats

The normalizer accepts Algerian mobile numbers in these forms:

- `0XXXXXXXXX`
- `+213XXXXXXXXX`
- `213XXXXXXXXX`
- `00213XXXXXXXXX`

Only DZ mobile prefixes are accepted in this phase:

- `05`
- `06`
- `07`

Landlines and non-DZ numbers are rejected.

## Main components

- Service: `App\Domain\Identity\Phone\PhoneNormalizer`
- Result DTO: `App\Domain\Identity\Phone\NormalizedPhoneResult`
- Validation rule: `App\Rules\DzMobilePhone`
- Backfill command: `php artisan phones:normalize-dz`

## Backfill command

Use the command below to normalize legacy data and generate a report:

```bash
php artisan phones:normalize-dz --dry-run
php artisan phones:normalize-dz
```

The report is written to:

- `storage/logs/phone-normalization.csv`

The command updates valid rows and reports invalid or conflicting rows without overwriting ambiguous canonical values.
