<?php

namespace App\Model\Entities\Security;

use App\Model\Entities\BaseEntity;
use App\Model\Entities\Templates\BaseTemplate;
use App\Model\Interfaces\ITemplate;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Rule extends BaseEntity
{
    const ALLOW = true;
    const DENY = false;

    /**
     * @ORM\Column(type="string")
     */
    protected $state;
    /**
     * @ORM\Column(type="boolean")
     */
    protected $type;

    /**
     * @ORM\Column(type="string")
     */
    protected $action;
    /**
     * @ORM\Column(type="boolean")
     */
    protected $isAppliedToOwner;
    /**
     * @var Role
     * @ORM\ManyToOne(targetEntity="Role")
     */
    protected $role;
    /**
     * @var ITemplate
     * @ORM\ManyToOne(targetEntity="App\Model\Entities\Templates\BaseTemplate")
     */
    protected $template;

    /**
     * Rule constructor.
     * @param $type
     */
    public function __construct($type)
    {
        $this->type = $type;
        $this->applyToOwner(false);
    }

    /**
     * @return mixed
     */
    public function getState()
    {
        return $this->state;
    }

    /**
     * @param mixed $state
     */
    public function setState($state)
    {
        $this->state = $state;
    }

    /**
     * @return mixed
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @return mixed
     */
    public function getAction()
    {
        return $this->action;
    }

    /**
     * @param mixed $action
     */
    public function setAction($action)
    {
        $this->action = $action;
    }

    /**
     * @return bool
     */
    public function isAppliedToOwner() : bool
    {
        return $this->isAppliedToOwner;
    }

    /**
     * @param bool $apply
     */
    public function applyToOwner($apply = true)
    {
        $this->isAppliedToOwner = $apply;
    }

    /**
     * @return Role
     */
    public function getRole() : Role
    {
        return $this->role;
    }

    /**
     * @param Role $role
     */
    public function setRole(Role $role)
    {
        $this->role = $role;
    }

    /**
     * @return ITemplate
     */
    public function getTemplate() : ITemplate
    {
        return $this->template;
    }

    /**
     * @param ITemplate $template
     */
    public function setTemplate(ITemplate $template)
    {
        $this->template = $template;
    }

}