<?php
 /*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the
 * LICENSE file in the root directory of this source tree.
 */

namespace FacebookPixelPlugin\FacebookAds\Object\CustomAudienceNormalizers;

use FacebookPixelPlugin\FacebookAds\Object\Fields\CustomAudienceMultikeySchemaFields;
use FacebookPixelPlugin\FacebookAds\Object\CustomAudienceNormalizers\ValueNormalizerInterface;

class FirstNameInitialNormalizer implements ValueNormalizerInterface {

  /**
   * @param string $key
   * @param string $key_value
   * @return boolean
   */
  public function shouldNormalize($key, $key_value) {
    return $key === CustomAudienceMultikeySchemaFields::FIRST_NAME_INITIAL;
  }

  /**
   * @param string $key
   * @param string $key_value
   * @return string
   */
  public function normalize($key, $key_value) {
    return preg_replace(
      '/[^a-z]/',
      '',
      strtolower(trim($key_value)))[0];
  }
}
