<?php

namespace FSpires\CommitKeeperBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * FSpires\CommitKeeperBundle\Entity\UserBase
 * Abstract base class for the classes User and UserName
 *
 * @ORM\Table(name="user")
 * @ORM\MappedSuperclass
 */
class UserBase implements \Serializable
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string $firstName
     *
     * @ORM\Column(name="first_name", type="string", length=100, nullable=false)
     */
    private $firstName;

    /**
     * @var string $middleName
     *
     * @ORM\Column(name="middle_name", type="string", length=100, nullable=false)
     */
    private $middleName;

    /**
     * @var string $lastName
     *
     * @ORM\Column(name="last_name", type="string", length=100, nullable=false)
     */
    private $lastName;

    /**
     * @var string $email
     *
     * @ORM\Column(name="email", type="string", length=200, nullable=false)
     */
    protected $email;

    /**
     * Get userId
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set firstName
     *
     * @param string $firstName
     */
    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;
    }

    /**
     * Get Name
     *
     * @return string 
     */
    public function getName()
    {
      $name = $this->firstName;
      if ($this->middleName) {
        $name .= ' ' . $this->middleName;
      }
      if ($this->lastName) {
        $name .= ' ' . $this->lastName;
      }
      return trim($name);
    }

    /**
     * Get firstName
     *
     * @return string 
     */
    public function getFirstName()
    {
        return $this->firstName;
    }

    /**
     * Set middleName
     *
     * @param string $middleName
     */
    public function setMiddleName($middleName)
    {
        $this->middleName = $middleName;
    }

    /**
     * Get middleName
     *
     * @return string 
     */
    public function getMiddleName()
    {
        return $this->middleName;
    }

    /**
     * Set lastName
     *
     * @param string $lastName
     */
    public function setLastName($lastName)
    {
        $this->lastName = $lastName;
    }

    /**
     * Get lastName
     *
     * @return string 
     */
    public function getLastName()
    {
        return $this->lastName;
    }

    /**
     * Set email
     *
     * @param string $email
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    public function serialize()
    {
        return serialize(array(
                 $this->id,
                 $this->firstName,
                 $this->middleName,
                 $this->lastName,
                 $this->email
                               ));
    }

    public function unserialize($str)
    {
        list(
                 $this->id,
                 $this->firstName,
                 $this->middleName,
                 $this->lastName,
                 $this->email
             ) = unserialize($str);
    }
}
