<?php

namespace App\Entity;

use App\Repository\ProductDocRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Attribute\Uploadable;
use Vich\UploaderBundle\Mapping\Attribute\UploadableField;

#[ORM\Entity(repositoryClass: ProductDocRepository::class)]
#[Uploadable]
class ProductDoc
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'productDocs')]
    private ?Product $product = null;

    #[ORM\Column(length: 255)]
    private ?string $name = null;

    #[ORM\Column]
    private ?bool $isPublic = null;

    #[UploadableField(mapping: 'doc_product', fileNameProperty: 'docProductName', size: 'docProductSize')]
    private ?File $docProduct = null;
    #[ORM\Column(nullable: true)]
    private ?string $docProductName = null;

    #[ORM\Column(nullable: true)]
    private ?int $docProductSize = null;

    #[ORM\Column(nullable: true)]
    private ?\DateTimeImmutable $updatedAt = null;


    public function json()
    {
        return json_encode([
           'name' => $this->name,
           'product' => $this->product->getName(),
        ]);
    }
    public function getId(): ?int
    {
        return $this->id;
    }

    public function getProduct(): ?Product
    {
        return $this->product;
    }

    public function setProduct(?Product $product): static
    {
        $this->product = $product;

        return $this;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): static
    {
        $this->name = $name;

        return $this;
    }

    public function isPublic(): ?bool
    {
        return $this->isPublic;
    }

    public function setIsPublic(bool $isPublic): static
    {
        $this->isPublic = $isPublic;

        return $this;
    }

    /**
     * @return \DateTimeImmutable|null
     */
    public function getUpdatedAt(): ?\DateTimeImmutable
    {
        return $this->updatedAt;
    }

    /**
     * @return File|null
     */
    public function getDocProduct(): ?File
    {
        return $this->docProduct;
    }

    /**
     * @return string|null
     */
    public function getDocProductName(): ?string
    {
        return $this->docProductName;
    }

    /**
     * @return int|null
     */
    public function getDocProductSize(): ?int
    {
        return $this->docProductSize;
    }

    /**
     * @param \DateTimeImmutable|null $updatedAt
     */
    public function setUpdatedAt(?\DateTimeImmutable $updatedAt): void
    {
        $this->updatedAt = $updatedAt;
    }

    /**
     * @param File|null $docProduct
     */
    public function setDocProduct(?File $docProduct): void
    {
        $this->docProduct = $docProduct;
    }

    /**
     * @param string|null $docProductName
     */
    public function setDocProductName(?string $docProductName): void
    {
        $this->docProductName = $docProductName;
    }

    /**
     * @param int|null $docProductSize
     */
    public function setDocProductSize(?int $docProductSize): void
    {
        $this->docProductSize = $docProductSize;
    }
}
