<?php 
 
namespace App\Entity; 
 
use App\Entity\Library; 
use App\Entity\Part; 
use App\Repository\CompanyRepository; 
use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\Common\Collections\Collection; 
use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\HttpFoundation\File\File; 
use Vich\UploaderBundle\Mapping\Annotation as Vich; 
use Symfony\Component\Validator\Constraints as Assert; 
use Symfony\Component\Serializer\Annotation\Groups; 
 
/** 
 * @ORM\Entity(repositoryClass=CompanyRepository::class) 
 * @Vich\Uploadable 
 *  
 * @ORM\Table(name="company",indexes={ 
 *     @ORM\Index(name="company_certifications", columns={"certifications"}), 
 *     @ORM\Index(name="company_name", columns={"name"}) 
 * }) 
 */ 
class Company 
{ 
    /** 
     * @ORM\Id 
     * @ORM\GeneratedValue 
     * @ORM\Column(type="integer") 
     * @Groups({"company"}) 
     */ 
    private $id;  
 
    /** 
     * @ORM\Column(type="string", length=100) 
     * @Assert\NotBlank 
     * @Groups({"company"}) 
     */ 
    private $name; 
 
    /** 
     * @ORM\OneToMany(targetEntity=User::class, mappedBy="company") 
     * @Groups({"company"}) 
     */ 
    private $user; 
 
    /** 
     * @ORM\Column(type="datetime") 
     * @Groups({"company"}) 
     */ 
    private $created_at; 
 
    /** 
     * @ORM\OneToMany(targetEntity=Library::class, mappedBy="company", orphanRemoval=false) 
     */ 
    private $libraries; 
 
    /** 
     * @ORM\OneToMany(targetEntity=Part::class, mappedBy="Company") 
     */ 
    private $parts; 
 
    /** 
     * @ORM\Column(type="string", length=20) 
     * @Assert\NotBlank 
     * @Groups({"company"}) 
     */ 
    private $nif; 
 
    /** 
     * @ORM\Column(type="string", length=50) 
     * @Assert\NotBlank 
     * @Groups({"company"}) 
     */ 
    private $phone; 
 
    /** 
     * @ORM\Column(type="string", length=100) 
     * @Assert\NotBlank 
     * @Assert\Email() 
     * @Groups({"company"}) 
     */ 
    private $email; 
 
    /** 
     * @ORM\Column(type="string", length=255) 
     * @Assert\NotBlank 
     * @Groups({"company"}) 
     */ 
    private $address; 
 
    /** 
     * @ORM\Column(type="datetime", nullable=true) 
     * @Groups({"company"}) 
     */ 
    private $updated_at; 
 
    /** 
     * @ORM\Column(type="string", length=4, unique=true) 
     * @Groups({"company"}) 
     */ 
    private $ref; 
 
    /** 
     * @ORM\OneToMany(targetEntity=CompanySupplier::class, mappedBy="company") 
     */ 
    private $companySuppliers; 
 
    /** 
     * @ORM\OneToMany(targetEntity=LicenseCompany::class, mappedBy="company") 
     */ 
    private $licenseCompanies; 
 
    /** 
     * 1: Client, 2:Supplier 
     *  
     * @ORM\OneToMany(targetEntity=Supplier::class, mappedBy="company") 
     */ 
    private $suppliers; 
 
    /** 
     * 1:OEM (Cliente), 2:Service bureau (Proveedor) 
     *  
     * @ORM\Column(type="integer") 
     * @Groups({"company"}) 
     */ 
    private $type; 
 
    /** 
     * @ORM\ManyToOne(targetEntity=LicenseCompany::class) 
     * @ORM\JoinColumn(onDelete="SET NULL") 
     */ 
    private $licenseCompany; 
 
    /** 
     * @ORM\Column(type="string", length=510, nullable=true) 
     * @Assert\Length( 
     *      max = 510 
     * ) 
     * @Groups({"company"}) 
     */ 
    private $certifications; 
 
    /** 
     * @ORM\Column(type="string", length=255, nullable=true) 
     * @Groups({"company"}) 
     * @Assert\Length( 
     *      max = 255 
     * ) 
     */ 
    private $services; 
 
    /** 
     * @ORM\Column(type="string", length=255, nullable=true) 
     * @Groups({"company"}) 
     * @Assert\Length( 
     *      max = 255 
     * ) 
     */ 
    private $web_page; 
 
    /** 
     * @ORM\Column(type="string", length=255, nullable=true) 
     * @Groups({"company"}) 
     */ 
    private $logo; 
 
    /** 
     * NOTE: This is not a mapped field of entity metadata, just a simple property. 
     *  
     * @Vich\UploadableField(mapping="company_file", fileNameProperty="logo") 
     * @Assert\File( 
     *     maxSize = "2M", 
     *     mimeTypes = {"image/jpeg","image/gif","image/png"}, 
     *     maxSizeMessage = "El tamaño máximo permitido del archivo es {{ limit }} MB.", 
     *     mimeTypesMessage = "El tipo de archivo no es válido ({{ type }}). Tipos de archivo permitidos {{ types }}" 
     * ) 
     *  
     * @var File|null 
     */ 
    private $logoFile; 
 
    /** 
     * @ORM\Column(type="string", length=510, nullable=true) 
     * @Groups({"company"}) 
     * @Assert\Length( 
     *      max = 510 
     * ) 
     */ 
    private $description; 
 
    /** 
     * @ORM\OneToMany(targetEntity=Equipment::class, mappedBy="company") 
     */ 
    private $equipment; 
 
    /** 
     * @ORM\OneToMany(targetEntity=Material::class, mappedBy="company") 
     */ 
    private $materials; 
 
    /** 
     * @ORM\OneToMany(targetEntity=CompanyAddress::class, mappedBy="company") 
     */ 
    private $companyAddresses; 
 
    /** 
     * @ORM\Column(type="smallint", nullable=true) 
     */ 
    private $currency; 
 
    /** 
     * @ORM\Column(type="smallint", nullable=true) 
     */ 
    private $thema; 
 
    /** 
     * @ORM\Column(type="string", length=10, nullable=true) 
     */ 
    private $color; 
 
    /** 
     * @ORM\OneToMany(targetEntity=CompanyClient::class, mappedBy="company") 
     */ 
    private $companyClients; 
 
    /** 
     * @ORM\Column(type="string", length=10, nullable=true) 
     */ 
    private $corporate_color; 
 
    /** 
     * 1:oscuro, 2:claro 
     *  
     * @ORM\Column(type="smallint", nullable=true) 
     */ 
    private $corporate_theme; 
 
    public function __construct() 
    { 
        $this->user = new ArrayCollection(); 
        $this->created_at = new \DateTime(); 
        $this->markAsUpdated(); 
        $this->libraries = new ArrayCollection(); 
        $this->parts = new ArrayCollection(); 
        $this->companySuppliers = new ArrayCollection(); 
        $this->licenseCompanies = new ArrayCollection(); 
        $this->suppliers = new ArrayCollection(); 
        $this->equipment = new ArrayCollection(); 
        $this->materials = new ArrayCollection(); 
        $this->companyAddresses = new ArrayCollection(); 
        $this->companyClients = 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 getName(): ?string 
    { 
        return $this->name; 
    } 
 
    public function setName(string $name): self 
    { 
        $this->name = $name; 
 
        return $this; 
    } 
 
    /** 
     * @return Collection|User[] 
     */ 
    public function getUser(): Collection 
    { 
        return $this->user; 
    } 
 
    public function addUser(User $user): self 
    { 
        if (!$this->user->contains($user)) { 
            $this->user[] = $user; 
            $user->setCompany($this); 
        } 
 
        return $this; 
    } 
 
    public function removeUser(User $user): self 
    { 
        if ($this->user->removeElement($user)) { 
            // set the owning side to null (unless already changed) 
            if ($user->getCompany() === $this) { 
                $user->setCompany(null); 
            } 
        } 
 
        return $this; 
    } 
 
    public function getCreatedAt(): ?\DateTimeInterface 
    { 
        return $this->created_at; 
    } 
 
    /** 
     * @return Collection|Library[] 
     */ 
    public function getLibraries(): Collection 
    { 
        return $this->libraries; 
    } 
 
    public function addLibrary(Library $library): self 
    { 
        if (!$this->libraries->contains($library)) { 
            $this->libraries[] = $library; 
            $library->setCompany($this); 
        } 
 
        return $this; 
    } 
 
    public function removeLibrary(Library $library): self 
    { 
        if ($this->libraries->removeElement($library)) { 
            // set the owning side to null (unless already changed) 
            if ($library->getCompany() === $this) { 
                $library->setCompany(null); 
            } 
        } 
 
        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->setCompany($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->getCompany() === $this) { 
                $part->setCompany(null); 
            } 
        } 
 
        return $this; 
    } 
 
    public function getNif(): ?string 
    { 
        return $this->nif; 
    } 
 
    public function setNif(?string $nif): self 
    { 
        $this->nif = $nif; 
 
        return $this; 
    } 
 
    public function getPhone(): ?string 
    { 
        return $this->phone; 
    } 
 
    public function setPhone(?string $phone): self 
    { 
        $this->phone = $phone; 
 
        return $this; 
    } 
 
    public function getEmail(): ?string 
    { 
        return $this->email; 
    } 
 
    public function setEmail(?string $email): self 
    { 
        $this->email = $email; 
 
        return $this; 
    } 
 
    public function getAddress(): ?string 
    { 
        return $this->address; 
    } 
 
     
 
    public function setAddress(?string $address): self 
    { 
        $this->address = $address; 
 
        return $this; 
    } 
 
    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 getRef(): ?string 
    { 
        return $this->ref; 
    } 
 
    public function setRef(string $ref): self 
    { 
        $ref++; 
        $this->ref = $ref; 
 
        return $this; 
    } 
 
    /** 
     * @return Collection|CompanySupplier[] 
     */ 
    public function getCompanySuppliers(): Collection 
    { 
        return $this->companySuppliers; 
    } 
 
    public function addCompanySupplier(CompanySupplier $companySupplier): self 
    { 
        if (!$this->companySuppliers->contains($companySupplier)) { 
            $this->companySuppliers[] = $companySupplier; 
            $companySupplier->setCompany($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->getCompany() === $this) { 
                $companySupplier->setCompany(null); 
            } 
        } 
 
        return $this; 
    } 
 
    /** 
     * @return Collection<int, LicenseCompany> 
     */ 
    public function getLicenseCompanies(): Collection 
    { 
        return $this->licenseCompanies; 
    } 
 
    public function addLicenseCompany(LicenseCompany $licenseCompany): self 
    { 
        if (!$this->licenseCompanies->contains($licenseCompany)) { 
            $this->licenseCompanies[] = $licenseCompany; 
            $licenseCompany->setCompany($this); 
        } 
 
        return $this; 
    } 
 
    public function removeLicenseCompany(LicenseCompany $licenseCompany): self 
    { 
        if ($this->licenseCompanies->removeElement($licenseCompany)) { 
            // set the owning side to null (unless already changed) 
            if ($licenseCompany->getCompany() === $this) { 
                $licenseCompany->setCompany(null); 
            } 
        } 
 
        return $this; 
    } 
 
    /** 
     * @return Collection<int, Supplier> 
     */ 
    public function getSuppliers(): Collection 
    { 
        return $this->suppliers; 
    } 
 
    public function addSupplier(Supplier $supplier): self 
    { 
        if (!$this->suppliers->contains($supplier)) { 
            $this->suppliers[] = $supplier; 
            $supplier->setCompany($this); 
        } 
 
        return $this; 
    } 
 
    public function removeSupplier(Supplier $supplier): self 
    { 
        if ($this->suppliers->removeElement($supplier)) { 
            // set the owning side to null (unless already changed) 
            if ($supplier->getCompany() === $this) { 
                $supplier->setCompany(null); 
            } 
        } 
 
        return $this; 
    } 
 
    public function getType(): ?int 
    { 
        return $this->type; 
    } 
 
    public function setType(int $type): self 
    { 
        $this->type = $type; 
 
        return $this; 
    } 
 
    public function getLicenseCompany(): ?LicenseCompany 
    { 
        return $this->licenseCompany; 
    } 
 
    public function setLicenseCompany(?LicenseCompany $licenseCompany): self 
    { 
        $this->licenseCompany = $licenseCompany; 
 
        return $this; 
    } 
 
    public function getCertifications(): ?string 
    { 
        return $this->certifications; 
    } 
 
    public function setCertifications(string $certifications): self 
    { 
        $this->certifications = $certifications; 
 
        return $this; 
    } 
 
    public function getServices(): ?string 
    { 
        return $this->services; 
    } 
 
    public function setServices(?string $services): self 
    { 
        $this->services = $services; 
 
        return $this; 
    } 
 
    public function getWebPage(): ?string 
    { 
        return $this->web_page; 
    } 
 
    public function setWebPage(?string $web_page): self 
    { 
        $this->web_page = $web_page; 
 
        return $this; 
    } 
 
    public function getLogo(): ?string 
    { 
        return $this->logo; 
    } 
 
    public function setLogo(?string $logo): self 
    { 
        $this->logo = $logo; 
 
        return $this; 
    } 
 
    /** 
     * If manually uploading a file (i.e. not using Symfony Form) ensure an instance 
     * of 'UploadedFile' is injected into this setter to trigger the update. If this 
     * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter 
     * must be able to accept an instance of 'File' as the bundle will inject one here 
     * during Doctrine hydration. 
     * 
     * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile 
     */ 
    public function setLogoFile(?File $logoFile = null): void 
    { 
        $this->logoFile = $logoFile; 
 
        if (null !== $logoFile) { 
            // It is required that at least one field changes if you are using doctrine 
            // otherwise the event listeners won't be called and the file is lost 
            $this->markAsUpdated(); 
        } 
    } 
 
    public function getLogoFile(): ?File 
    { 
        return $this->logoFile; 
    } 
 
    public function getDescription(): ?string 
    { 
        return $this->description; 
    } 
 
    public function setDescription(?string $description): self 
    { 
        $this->description = $description; 
 
        return $this; 
    } 
 
    /** 
     * @return Collection<int, Equipment> 
     */ 
    public function getEquipment(): Collection 
    { 
        return $this->equipment; 
    } 
 
    public function addEquipment(Equipment $equipment): self 
    { 
        if (!$this->equipment->contains($equipment)) { 
            $this->equipment[] = $equipment; 
            $equipment->setCompany($this); 
        } 
 
        return $this; 
    } 
 
    public function removeEquipment(Equipment $equipment): self 
    { 
        if ($this->equipment->removeElement($equipment)) { 
            // set the owning side to null (unless already changed) 
            if ($equipment->getCompany() === $this) { 
                $equipment->setCompany(null); 
            } 
        } 
 
        return $this; 
    } 
 
    /** 
     * @return Collection<int, Material> 
     */ 
    public function getMaterials(): Collection 
    { 
        return $this->materials; 
    } 
 
    public function addMaterial(Material $material): self 
    { 
        if (!$this->materials->contains($material)) { 
            $this->materials[] = $material; 
            $material->setCompany($this); 
        } 
 
        return $this; 
    } 
 
    public function removeMaterial(Material $material): self 
    { 
        if ($this->materials->removeElement($material)) { 
            // set the owning side to null (unless already changed) 
            if ($material->getCompany() === $this) { 
                $material->setCompany(null); 
            } 
        } 
 
        return $this; 
    } 
 
    /** 
     * @return Collection<int, CompanyAddress> 
     */ 
    public function getCompanyAddresses(): Collection 
    { 
        return $this->companyAddresses; 
    } 
 
    public function addCompanyAddress(CompanyAddress $companyAddress): self 
    { 
        if (!$this->companyAddresses->contains($companyAddress)) { 
            $this->companyAddresses[] = $companyAddress; 
            $companyAddress->setCompany($this); 
        } 
 
        return $this; 
    } 
 
    public function removeCompanyAddress(CompanyAddress $companyAddress): self 
    { 
        if ($this->companyAddresses->removeElement($companyAddress)) { 
            // set the owning side to null (unless already changed) 
            if ($companyAddress->getCompany() === $this) { 
                $companyAddress->setCompany(null); 
            } 
        } 
 
        return $this; 
    } 
 
    public function getCurrency(): ?int 
    { 
        return $this->currency; 
    } 
 
    public function setCurrency(int $currency): self 
    { 
        $this->currency = $currency; 
 
        return $this; 
    } 
 
    public function getThema(): ?int 
    { 
        return $this->thema; 
    } 
 
    public function setThema(int $thema): self 
    { 
        $this->thema = $thema; 
 
        return $this; 
    } 
 
    public function getColor(): ?string 
    { 
        return $this->color; 
    } 
 
    public function setColor(?string $color): self 
    { 
        $this->color = $color; 
 
        return $this; 
    } 
 
    /** 
     * @return Collection<int, CompanyClient> 
     */ 
    public function getCompanyClients(): Collection 
    { 
        return $this->companyClients; 
    } 
 
    public function addCompanyClient(CompanyClient $companyClient): self 
    { 
        if (!$this->companyClients->contains($companyClient)) { 
            $this->companyClients[] = $companyClient; 
            $companyClient->setCompany($this); 
        } 
 
        return $this; 
    } 
 
    public function removeCompanyClient(CompanyClient $companyClient): self 
    { 
        if ($this->companyClients->removeElement($companyClient)) { 
            // set the owning side to null (unless already changed) 
            if ($companyClient->getCompany() === $this) { 
                $companyClient->setCompany(null); 
            } 
        } 
 
        return $this; 
    } 
 
    public function getCorporateColor(): ?string 
    { 
        return $this->corporate_color; 
    } 
 
    public function setCorporateColor(?string $corporate_color): self 
    { 
        $this->corporate_color = $corporate_color; 
 
        return $this; 
    } 
 
    public function getCorporateTheme(): ?int 
    { 
        return $this->corporate_theme; 
    } 
 
    public function setCorporateTheme(?int $corporate_theme): self 
    { 
        $this->corporate_theme = $corporate_theme; 
 
        return $this; 
    } 
     
}