<?php

namespace AppBundle\Entity\Traits;

use AppBundle\Enum\Core\ContactPointTypeEnum;

/**
 * Description of ContactPointType
 *
 * @author Sébastien Hupin <sebastien.hupin at gmail.com>
 */
trait ContactPointType
{
  /**
   * 
   * @param string $type
   * @return \AppBundle\Entity\Core\ContactPoint or null
   */
  public function getContactPointForType($type) {
    $contactPointEnum = new ContactPointTypeEnum($type);
    if ($this->getContactPoint()) {
      foreach($this->getContactPoint() as $contactPoint) {
        if ($contactPointEnum->getValue() === $contactPoint->getContactType()) {
          return $contactPoint;
        }
      }
    }
    return null;
  }
  
  /**
   * 
   * @return \AppBundle\Entity\Core\ContactPoint or null
   */
  public function getContactPointPrincipal() {
    return $this->getContactPointForType(ContactPointTypeEnum::PRINCIPAL);
  }
  
}

?>
