<?php

class Profile implements \JsonSerializable{
  private $locale;
  private $firstName;
  private $lastName;
  private $email;
  private $phone;
  private $dateOfBirth;

	/*use SetterTrait;
	use GetterTrait;
	use JsonSerializeTrait;*/

  public function __construct($data = null){
    if($data !== null){
      foreach($data as $key => $value){
        if($key == "dateOfBirth"){
          $dob = new DateOfBirth($value);
          $this->dateOfBirth = $dob;
        }else{
          $this->$key = $value;
        }
      }
    }
  }

  protected function setLocale($locale){
    $this->locale = $locale;
  }

  protected function setFirstName($firstName){
		$this->firstName = $firstName;
  }
    
  protected function setLastName($lastName){
		$this->lastName = $lastName;
  }

  protected function setEmail($email){
    $this->email = $email;
  }

  protected function setPhone($phone){
    $this->phone = $phone;
  }

  protected function setDateOfBirth(DateOfBirth $dateOfBirth){
    $this->dateOfBirth = $dateOfBirth;
  }

    public function __set($name, $value)
    {
        $setter = 'set'.$name;
        if (method_exists($this, $setter)) {
            $this->$setter($value);
        } else {
            $this->$name = $value;
        }
    }

    public function __get($name){
        return $this->$name;
    }

    public function jsonSerialize()
    {
        $vars = array_filter(get_object_vars($this), function($val){ return $val !== null; });
        return $vars;
    }
}
