<?php

namespace AppBundle\Entity\Core;

use AppBundle\Entity\AccessAndFunction\Access;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Annotation\ORM as OpentalentORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
* @OpentalentORM\View(query="
CREATE OR REPLACE VIEW opentalent.view_audit AS
(SELECT
init_var_session() as identifier,
null as rev,
a.id,
null as createDate,
null as updateDate,
null as createdBy_id,
null as updatedBy_id,
null as revType,
null as organizationId,
'INIT' as tableName
FROM
Audit_Organization a
LIMIT 1)
UNION
(SELECT
func_inc_var_session() as identifier,
person.rev,
person.id,
person.createDate,
person.updateDate,
person.createdBy as createdBy_id,
person.updatedBy as updatedBy_id,
person.revType,
IF(Access.organization_id IS NOT NULL,
Access.organization_id,
accessPerson2.organization_id) as organizationId,
'person' as tableName
FROM
opentalent.Audit_Person AS person
LEFT JOIN
Access ON Access.id = person.createdBy
LEFT JOIN
Access as accessPerson2 ON accessPerson2.id = person.updatedBy
WHERE
(Access.organization_id IS NOT NULL
OR accessPerson2.organization_id IS NOT NULL))
UNION
(SELECT
func_inc_var_session() as identifier,
donor.rev,
donor.id,
donor.createDate,
donor.updateDate,
donor.createdBy as createdBy_id,
donor.updatedBy as updatedBy_id,
donor.revType,
Access.organization_id,
'donor' as tableName
FROM
opentalent.Audit_Donor as donor
INNER JOIN
Access ON donor.access_id = Access.id)
ORDER BY updateDate DESC , createDate DESC")
*/
#[ORM\Entity(readOnly: true)]
#[ORM\Table(name: 'view_audit')]
class ViewAudit
{
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $identifier;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $id;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $rev;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'datetime')]
    #[Assert\Date]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $createDate;
    /**
     * @var \DateTime
     */
    #[ORM\Column(type: 'datetime')]
    #[Assert\Date]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $updateDate;
    /**
     * @var Access
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access')]
    #[ORM\JoinColumn(nullable: true)]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $createdBy;
    /**
     * @var Access
     */
    #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\AccessAndFunction\Access')]
    #[ORM\JoinColumn(nullable: true)]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $updatedBy;
    /**
     *
     * @var string
     */
    #[ORM\Column(type: 'string', length: 40)]
    #[Assert\Type(type: 'string')]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $revType;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $organizationId;
    /**
     *
     * @var string
     */
    #[ORM\Column(type: 'string', length: 40)]
    #[Assert\Type(type: 'string')]
    #[Groups(['viewaudit', 'viewaudit_list'])]
    private $tableName;
    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }
    /**
     * Set rev
     *
     * @param integer $rev
     *
     * @return ViewAudit
     */
    public function setRev($rev)
    {
        $this->rev = $rev;

        return $this;
    }
    /**
     * Get rev
     *
     * @return integer
     */
    public function getRev()
    {
        return $this->rev;
    }
    /**
     * Set createDate
     *
     * @param \DateTime $createDate
     *
     * @return ViewAudit
     */
    public function setCreateDate($createDate)
    {
        $this->createDate = $createDate;

        return $this;
    }
    /**
     * Get createDate
     *
     * @return \DateTime
     */
    public function getCreateDate()
    {
        return $this->createDate;
    }
    /**
     * Set updateDate
     *
     * @param \DateTime $updateDate
     *
     * @return ViewAudit
     */
    public function setUpdateDate($updateDate)
    {
        $this->updateDate = $updateDate;

        return $this;
    }
    /**
     * Get updateDate
     *
     * @return \DateTime
     */
    public function getUpdateDate()
    {
        return $this->updateDate;
    }
    /**
     * Set revType
     *
     * @param string $revType
     *
     * @return ViewAudit
     */
    public function setRevType($revType)
    {
        $this->revType = $revType;

        return $this;
    }
    /**
     * Get revType
     *
     * @return string
     */
    public function getRevType()
    {
        return $this->revType;
    }
    /**
     * Set organizationId
     *
     * @param integer $organizationId
     *
     * @return ViewAudit
     */
    public function setOrganizationId($organizationId)
    {
        $this->organizationId = $organizationId;

        return $this;
    }
    /**
     * Get organizationId
     *
     * @return integer
     */
    public function getOrganizationId()
    {
        return $this->organizationId;
    }
    /**
     * Set tableName
     *
     * @param string $tableName
     *
     * @return ViewAudit
     */
    public function setTableName($tableName)
    {
        $this->tableName = $tableName;

        return $this;
    }
    /**
     * Get tableName
     *
     * @return string
     */
    public function getTableName()
    {
        return $this->tableName;
    }
    /**
     * Set createdBy
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $createdBy
     *
     * @return ViewAudit
     */
    public function setCreatedBy(\AppBundle\Entity\AccessAndFunction\Access $createdBy = null)
    {
        $this->createdBy = $createdBy;

        return $this;
    }
    /**
     * Get createdBy
     *
     * @return \AppBundle\Entity\AccessAndFunction\Access
     */
    public function getCreatedBy()
    {
        return $this->createdBy;
    }
    /**
     * Set updatedBy
     *
     * @param \AppBundle\Entity\AccessAndFunction\Access $updatedBy
     *
     * @return ViewAudit
     */
    public function setUpdatedBy(\AppBundle\Entity\AccessAndFunction\Access $updatedBy = null)
    {
        $this->updatedBy = $updatedBy;

        return $this;
    }
    /**
     * Get updatedBy
     *
     * @return \AppBundle\Entity\AccessAndFunction\Access
     */
    public function getUpdatedBy()
    {
        return $this->updatedBy;
    }
    /**
     * Get identifier
     *
     * @return integer
     */
    public function getIdentifier()
    {
        return $this->identifier;
    }
}
