<?php

namespace App\Services;

/**
 * Single source of truth for which Contact fields an inbound webhook form
 * can submit, their human labels, and the incoming key variants
 * WebhookFieldMapper auto-detects for each. Also powers the field-reference
 * lookup on the Contacts and Webhooks pages.
 */
class ContactFieldRegistry
{
    public const FIELDS = [
        'email'          => ['label' => 'Email',            'aliases' => ['email', 'email_address', 'emailaddress', 'e_mail', 'mail']],
        'prefix'         => ['label' => 'Prefix',            'aliases' => ['prefix', 'title', 'salutation']],
        'first_name'     => ['label' => 'First Name',       'aliases' => ['first_name', 'firstname', 'first', 'fname', 'given_name']],
        'last_name'      => ['label' => 'Last Name',        'aliases' => ['last_name', 'lastname', 'last', 'lname', 'surname', 'family_name']],
        'phone'          => ['label' => 'Phone',             'aliases' => ['phone', 'phone_number', 'phonenumber', 'mobile', 'telephone', 'tel']],
        'date_of_birth'  => ['label' => 'Date of Birth',     'aliases' => ['date_of_birth', 'dob', 'birthday', 'birth_date']],
        'address_line_1' => ['label' => 'Address Line 1',    'aliases' => ['address', 'address_line_1', 'address1', 'street', 'street_address']],
        'address_line_2' => ['label' => 'Address Line 2',    'aliases' => ['address_line_2', 'address2', 'apt', 'suite', 'unit']],
        'city'           => ['label' => 'City',              'aliases' => ['city', 'town']],
        'state'          => ['label' => 'State / Province',  'aliases' => ['state', 'province', 'region']],
        'postal_code'    => ['label' => 'Postal / Zip Code', 'aliases' => ['postal_code', 'zip', 'zip_code', 'zipcode', 'postcode']],
        'country'        => ['label' => 'Country',           'aliases' => ['country']],
    ];

    /** Field key => list of accepted incoming aliases. Used by WebhookFieldMapper. */
    public static function aliases(): array
    {
        return array_map(fn ($f) => $f['aliases'], self::FIELDS);
    }
}
