<?php 
 
namespace App\Entity; 
 
use App\Repository\SupplierRepository; 
use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\Common\Collections\Collection; 
use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\Validator\Constraints as Assert; 
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; 
 
/** 
 * @ORM\Entity(repositoryClass=SupplierRepository::class) 
 */ 
class Supplier 
{ 
    /** 
     * @ORM\Id 
     * @ORM\GeneratedValue 
     * @ORM\Column(type="integer") 
     */ 
    private $id; 
 
    /** 
     * @ORM\Column(type="string", length=4) 
     */ 
    private $ref; 
 
    /** 
     * @ORM\Column(type="string", length=255, nullable=true) 
     * @Assert\NotBlank 
     */ 
    private $name; 
 
    /** 
     * @ORM\Column(type="string", length=100, nullable=true, options={"default" : 1}) 
     */ 
    private $objective; 
 
    /** 
     * @ORM\Column(type="string", length=255, nullable=true) 
     * @Assert\NotBlank 
     */ 
    private $address; 
 
    /** 
     * @ORM\Column(type="integer", nullable=true) 
     */ 
    private $phone; 
 
    /** 
     * @ORM\Column(type="string", length=100, nullable=true) 
     */ 
    private $cif; 
 
    /** 
     * @ORM\Column(type="string", length=255, nullable=true) 
     */ 
    private $work_center; 
 
    /** 
     * @ORM\Column(type="string", length=255, nullable=true) 
     */ 
    private $contact; 
 
    /** 
     * @ORM\Column(type="string", length=255) 
     */ 
    private $certifications; 
 
    /** 
     * @ORM\Column(type="string", length=255, nullable=true) 
     */ 
    private $notes; 
 
    /** 
     * @ORM\Column(type="string", length=255, nullable=true) 
     */ 
    private $others; 
 
    /** 
     * @ORM\Column(type="datetime", nullable=true) 
     */ 
    private $created_at; 
 
    /** 
     * @ORM\Column(type="datetime", nullable=true) 
     */ 
    private $updated_at; 
 
    /** 
     * @ORM\OneToOne(targetEntity=User::class, cascade={"persist", "remove"}) 
     * @ORM\JoinColumn(onDelete="CASCADE") 
     */ 
    private $user; 
 
    /** 
     * @ORM\OneToMany(targetEntity=Part::class, mappedBy="supplier") 
     */ 
    private $parts; 
 
    /** 
     * @ORM\OneToMany(targetEntity=User::class, mappedBy="supplier") 
     */ 
    private $users; 
 
    /** 
     * @ORM\OneToMany(targetEntity=CompanySupplier::class, mappedBy="supplier") 
     */ 
    private $companySuppliers; 
 
    /** 
     * Permite colaboraciones externas 
     * 
     * @ORM\Column(type="boolean") 
     */ 
    private $collab; 
 
    /** 
     * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="suppliers") 
     * @ORM\JoinColumn(onDelete="CASCADE") 
     * @ORM\JoinColumn(nullable=false) 
     */ 
    private $company; 
 
    /** 
     * @ORM\Column(type="string", length=100, nullable=true) 
     * 
     * @Assert\Email( 
     *     message = "El email '{{ value }}' no es válido." 
     * ) 
     */ 
    private $email; 
 
    /** 
     * @ORM\Column(type="boolean", nullable=true) 
     */ 
    private $marketplace; 
 
    public function __construct() 
    { 
        $this->created_at = new \DateTime(); 
        $this->markAsUpdated(); 
        $this->parts = new ArrayCollection(); 
        $this->users = new ArrayCollection(); 
        $this->companySuppliers = new ArrayCollection(); 
    } 
 
    // Registra el método mágico para imprimir el nombre del estado, por ejemplo, California 
    public function __toString() { 
        return $this->name; 
    } 
 
    public function getId(): ?int 
    { 
        return $this->id; 
    } 
 
    public function getRef(): ?string 
    { 
        return $this->ref; 
    } 
 
    public function setRef(string $ref): self 
    { 
        $ref++; 
        $this->ref = $ref; 
 
        return $this; 
    } 
 
    public function getName(): ?string 
    { 
        return $this->name; 
    } 
 
    public function setName(?string $name): self 
    { 
        $this->name = $name; 
 
        return $this; 
    } 
 
    public function getAddress(): ?string 
    { 
        return $this->address; 
    } 
 
    public function setAddress(?string $address): self 
    { 
        $this->address = $address; 
 
        return $this; 
    } 
 
    public function getPhone(): ?int 
    { 
        return $this->phone; 
    } 
 
    public function setPhone(?int $phone): self 
    { 
        $this->phone = $phone; 
 
        return $this; 
    } 
 
    public function getCif(): ?string 
    { 
        return $this->cif; 
    } 
 
    public function setCif(?string $cif): self 
    { 
        $this->cif = $cif; 
 
        return $this; 
    } 
 
    public function getWorkCenter(): ?string 
    { 
        return $this->work_center; 
    } 
 
    public function setWorkCenter(?string $work_center): self 
    { 
        $this->work_center = $work_center; 
 
        return $this; 
    } 
 
    public function getContact(): ?string 
    { 
        return $this->contact; 
    } 
 
    public function setContact(?string $contact): self 
    { 
        $this->contact = $contact; 
 
        return $this; 
    } 
 
    public function getCertifications(): ?string 
    { 
        return $this->certifications; 
    } 
 
    public function setCertifications(string $certifications): self 
    { 
        $this->certifications = $certifications; 
 
        return $this; 
    } 
 
    public function getNotes(): ?string 
    { 
        return $this->notes; 
    } 
 
    public function setNotes(?string $notes): self 
    { 
        $this->notes = $notes; 
 
        return $this; 
    } 
 
    public function getOthers(): ?string 
    { 
        return $this->others; 
    } 
 
    public function setOthers(?string $others): self 
    { 
        $this->others = $others; 
 
        return $this; 
    } 
 
    public function getCreatedAt(): ?\DateTimeInterface 
    { 
        return $this->created_at; 
    } 
 
    public function getUpdatedAt(): ?\DateTimeInterface 
    { 
        return $this->updated_at; 
    } 
 
    /** 
     * Set the value of updatedAt 
     * 
     * @param \DateTime $updatedAt 
     */ 
    public function markAsUpdated() : void 
    { 
        $this->updated_at = new \DateTime(); 
    } 
 
    public function getUser(): ?User 
    { 
        return $this->user; 
    } 
 
    public function setUser(User $user): self 
    { 
        $this->user = $user; 
 
        return $this; 
    } 
 
    /** 
     * @return Collection|Part[] 
     */ 
    public function getParts(): Collection 
    { 
        return $this->parts; 
    } 
 
    public function addPart(Part $part): self 
    { 
        if (!$this->parts->contains($part)) { 
            $this->parts[] = $part; 
            $part->setSupplier($this); 
        } 
 
        return $this; 
    } 
 
    public function removePart(Part $part): self 
    { 
        if ($this->parts->removeElement($part)) { 
            // set the owning side to null (unless already changed) 
            if ($part->getSupplier() === $this) { 
                $part->setSupplier(null); 
            } 
        } 
 
        return $this; 
    } 
 
    /** 
     * @return Collection<int, User> 
     */ 
    public function getUsers(): Collection 
    { 
        return $this->users; 
    } 
 
    public function addUsers(User $users): self 
    { 
        if (!$this->users->contains($users)) { 
            $this->users[] = $users; 
            $users->setSupplier($this); 
        } 
 
        return $this; 
    } 
 
    public function removeUsers(User $users): self 
    { 
        if ($this->users->removeElement($users)) { 
            // set the owning side to null (unless already changed) 
            if ($users->getSupplier() === $this) { 
                $users->setSupplier(null); 
            } 
        } 
 
        return $this; 
    } 
 
    /** 
     * @return Collection<int, CompanySupplier> 
     */ 
    public function getCompanySuppliers(): Collection 
    { 
        return $this->companySuppliers; 
    } 
 
    public function addCompanySupplier(CompanySupplier $companySupplier): self 
    { 
        if (!$this->companySuppliers->contains($companySupplier)) { 
            $this->companySuppliers[] = $companySupplier; 
            $companySupplier->setSupplier($this); 
        } 
 
        return $this; 
    } 
 
    public function removeCompanySupplier(CompanySupplier $companySupplier): self 
    { 
        if ($this->companySuppliers->removeElement($companySupplier)) { 
            // set the owning side to null (unless already changed) 
            if ($companySupplier->getSupplier() === $this) { 
                $companySupplier->setSupplier(null); 
            } 
        } 
 
        return $this; 
    } 
 
    public function getCollab(): ?bool 
    { 
        return $this->collab; 
    } 
 
    public function setCollab(bool $collab): self 
    { 
        $this->collab = $collab; 
 
        return $this; 
    } 
 
    public function getCompany(): ?Company 
    { 
        return $this->company; 
    } 
 
    public function setCompany(?Company $company): self 
    { 
        $this->company = $company; 
 
        return $this; 
    } 
 
    public function getEmail(): ?string 
    { 
        return $this->email; 
    } 
 
    public function setEmail(?string $email): self 
    { 
        $this->email = $email; 
 
        return $this; 
    } 
 
    public function getMarketplace(): ?bool 
    { 
        return $this->marketplace; 
    } 
 
    public function setMarketplace(?bool $marketplace): self 
    { 
        $this->marketplace = $marketplace; 
 
        return $this; 
    } 
 
    /** 
     * @return mixed 
     */ 
    public function getObjective() 
    { 
        return $this->objective; 
    } 
 
    /** 
     * @param mixed $objective 
     */ 
    public function setObjective($objective): void 
    { 
        $this->objective = $objective; 
    } 
 
 
}