<?php

namespace App\Entity;

use App\Repository\WebrootFileRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: WebrootFileRepository::class,)]
#[ORM\Table(name:'mydevel_webroot_file')]
class WebrootFile
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 65535,nullable:false)]
    private ?string $url = null;
    
    
    #[ORM\Column(length: 65535,nullable:false)]
    private ?string $abspath = null;

    #[ORM\Column(length: 4095,nullable:true)]
    private ?string $description = null;

    /**
     * @var Collection<int, WebrootPermission>
     */
    #[ORM\OneToMany(targetEntity: WebrootFilePermission::class, mappedBy: 'webrootFile', orphanRemoval: true)]
    private Collection $permissions;

    #[ORM\OneToOne(cascade: ['persist', 'remove'])]
    #[ORM\JoinColumn(nullable: false)]
    private ?WebrootUser $owner = null;

    
    public function __construct()
    {
        $this->permissions = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getUrlPath(): ?string
    {
        return $this->url;
    }

    public function setUrlPath(string $url): static
    {
        $this->url = $url;

        return $this;
    }

    public function getAbspath(): ?string
    {
        return $this->abspath;
    }

    public function setAbspath(string $abspath): static
    {
        $this->abspath = $abspath;

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }
    
    public function setDescription(?string $description): static
    {
        $this->description = $description;
        
        return $this;
    }
    
    /**
     * @return Collection<int, WebrootPermission>
     */
    public function getPermissions(): Collection
    {
        return $this->permissions;
    }

    public function addPermission(WebrootPermission $permission): static
    {
        if (!$this->permissions->contains($permission)) {
            $this->permissions->add($permission);
            $permission->setWebrootFile($this);
        }

        return $this;
    }

    public function removePermission(WebrootFilePermission $permission): static
    {
        if ($this->permissions->removeElement($permission)) {
            // set the owning side to null (unless already changed)
            if ($permission->getWebrootFile() === $this) {
                $permission->setWebrootFile(null);
            }
        }

        return $this;
    }

    public function getOwner(): ?WebrootUser
    {
        return $this->owner;
    }

    public function setOwner(WebrootUser $owner): static
    {
        $this->owner = $owner;

        return $this;
    }
}
