<?php

namespace App\Entity;

use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

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

    #[ORM\Column(type: "integer", unique: true, nullable: true, options: ["unsigned" => true])]
    protected ?int $navisionId;

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

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

    #[ORM\ManyToOne(targetEntity: MediaObject::class)]
    #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
    private ?MediaObject $image = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private ?User $createdBy = null;

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

    #[ORM\Column]
    private ?float $inventory = null;

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

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

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

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

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

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

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

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

    #[ORM\Column]
    private ?\DateTimeImmutable $createdAt = null;

    #[ORM\OneToMany(mappedBy: 'product', targetEntity: Sale::class)]
    private Collection $sales;

    #[ORM\OneToMany(mappedBy: 'product', targetEntity: Document::class)]
    private Collection $documentObjects;

    #[ORM\OneToMany(mappedBy: 'product', targetEntity: Posting::class)]
    private Collection $postings;

    #[ORM\OneToMany(mappedBy: 'product', targetEntity: PartnerProduct::class)]
    private Collection $partnerProducts;

    #[ORM\OneToMany(mappedBy: 'product', targetEntity: UserProduct::class)]
    private Collection $userProducts;

    #[ORM\OneToMany(mappedBy: 'product', targetEntity: Task::class)]
    private Collection $tasks;

    public function __construct(User $createdBy)
    {
        $this->blocked = false;
        $this->inventory = 0.0;
        $this->createdBy = $createdBy;
        $this->createdAt = new \DateTimeImmutable();
        $this->sales = new ArrayCollection();
        $this->documentObjects = new ArrayCollection();
        $this->postings = new ArrayCollection();
        $this->partnerProducts = new ArrayCollection();
        $this->userProducts = new ArrayCollection();
        $this->tasks = new ArrayCollection();
    }

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

    public function getNavisionId(): ?int
    {
        return $this->navisionId;
    }

    public function setNavisionId(int $navisionId): void
    {
        $this->navisionId = $navisionId;
    }

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

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

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(?string $description): static
    {
        $this->description = $description;

        return $this;
    }

    public function getImage(): ?MediaObject
    {
        return $this->image;
    }

    public function setImage(?MediaObject $image): static
    {
        $this->image = $image;

        return $this;
    }

    public function getCreatedBy(): ?User
    {
        return $this->createdBy;
    }

    public function getCreatedAt(): ?\DateTimeImmutable
    {
        return $this->createdAt;
    }

    /**
     * @return Collection<int, Sale>
     */
    public function getSales(): Collection
    {
        return $this->sales;
    }

    public function addSale(Sale $sale): static
    {
        if (!$this->sales->contains($sale)) {
            $this->sales->add($sale);
            $sale->setProduct($this);
        }

        return $this;
    }

    public function removeSale(Sale $sale): static
    {
        if ($this->sales->removeElement($sale)) {
            // set the owning side to null (unless already changed)
            if ($sale->getProduct() === $this) {
                $sale->setProduct(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Document>
     */
    public function getDocumentObjects(): Collection
    {
        return $this->documentObjects;
    }

    public function addDocumentObject(Document $documentObject): static
    {
        if (!$this->documentObjects->contains($documentObject)) {
            $this->documentObjects->add($documentObject);
            $documentObject->setProduct($this);
        }

        return $this;
    }

    public function removeDocumentObject(Document $documentObject): static
    {
        if ($this->documentObjects->removeElement($documentObject)) {
            // set the owning side to null (unless already changed)
            if ($documentObject->getProduct() === $this) {
                $documentObject->setProduct(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Posting>
     */
    public function getPostings(): Collection
    {
        return $this->postings;
    }

    public function addPosting(Posting $posting): static
    {
        if (!$this->postings->contains($posting)) {
            $this->postings->add($posting);
            $posting->setProduct($this);
        }

        return $this;
    }

    public function removePosting(Posting $posting): static
    {
        if ($this->postings->removeElement($posting)) {
            // set the owning side to null (unless already changed)
            if ($posting->getProduct() === $this) {
                $posting->setProduct(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, PartnerProduct>
     */
    public function getPartnerProducts(): Collection
    {
        return $this->partnerProducts;
    }

    public function addPartnerProduct(PartnerProduct $partnerProduct): static
    {
        if (!$this->partnerProducts->contains($partnerProduct)) {
            $this->partnerProducts->add($partnerProduct);
            $partnerProduct->setProduct($this);
        }

        return $this;
    }

    public function removePartnerProduct(PartnerProduct $partnerProduct): static
    {
        if ($this->partnerProducts->removeElement($partnerProduct)) {
            // set the owning side to null (unless already changed)
            if ($partnerProduct->getProduct() === $this) {
                $partnerProduct->setProduct(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, UserProduct>
     */
    public function getUserProducts(): Collection
    {
        return $this->userProducts;
    }

    public function addUserProduct(UserProduct $userProduct): static
    {
        if (!$this->userProducts->contains($userProduct)) {
            $this->userProducts->add($userProduct);
            $userProduct->setProduct($this);
        }

        return $this;
    }

    public function removeUserProduct(UserProduct $userProduct): static
    {
        if ($this->userProducts->removeElement($userProduct)) {
            // set the owning side to null (unless already changed)
            if ($userProduct->getProduct() === $this) {
                $userProduct->setProduct(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Task>
     */
    public function getTasks(): Collection
    {
        return $this->tasks;
    }

    public function addTask(Task $task): static
    {
        if (!$this->tasks->contains($task)) {
            $this->tasks->add($task);
            $task->setProduct($this);
        }

        return $this;
    }

    public function removeTask(Task $task): static
    {
        if ($this->tasks->removeElement($task)) {
            // set the owning side to null (unless already changed)
            if ($task->getProduct() === $this) {
                $task->setProduct(null);
            }
        }

        return $this;
    }

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

    public function setBlocked(bool $blocked): static
    {
        $this->blocked = $blocked;

        return $this;
    }

    public function getInventory(): ?float
    {
        return $this->inventory;
    }

    public function setInventory(float $inventory): static
    {
        $this->inventory = $inventory;

        return $this;
    }

    public function getBaseUnit(): ?string
    {
        return $this->baseUnit;
    }

    public function setBaseUnit(?string $baseUnit): static
    {
        $this->baseUnit = $baseUnit;

        return $this;
    }

    public function getBuyUnit(): ?string
    {
        return $this->buyUnit;
    }

    public function setBuyUnit(?string $buyUnit): static
    {
        $this->buyUnit = $buyUnit;

        return $this;
    }

    public function getSellUnit(): ?string
    {
        return $this->sellUnit;
    }

    public function setSellUnit(?string $sellUnit): static
    {
        $this->sellUnit = $sellUnit;

        return $this;
    }

    public function getTrackingCode(): ?string
    {
        return $this->trackingCode;
    }

    public function setTrackingCode(?string $trackingCode): static
    {
        $this->trackingCode = $trackingCode;

        return $this;
    }

    public function getProductGroup(): ?string
    {
        return $this->productGroup;
    }

    public function setProductGroup(?string $productGroup): static
    {
        $this->productGroup = $productGroup;

        return $this;
    }

    public function getCustomsPosition(): ?string
    {
        return $this->customsPosition;
    }

    public function setCustomsPosition(?string $customsPosition): static
    {
        $this->customsPosition = $customsPosition;

        return $this;
    }

    public function getProductBookingGroup(): ?string
    {
        return $this->productBookingGroup;
    }

    public function setProductBookingGroup(?string $productBookingGroup): static
    {
        $this->productBookingGroup = $productBookingGroup;

        return $this;
    }

    public function getVatProductBookingGroup(): ?string
    {
        return $this->vatProductBookingGroup;
    }

    public function setVatProductBookingGroup(?string $vatProductBookingGroup): static
    {
        $this->vatProductBookingGroup = $vatProductBookingGroup;

        return $this;
    }
}
