<?php

namespace App\Entity;

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

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

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

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

    #[ORM\ManyToOne(inversedBy: 'contacts')]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private ?Partner $partner = null;

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

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

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

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

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

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

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

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

    #[ORM\OneToMany(mappedBy: 'contact', targetEntity: ContactPartnerProduct::class)]
    private Collection $contactPartnerProducts;

    #[ORM\OneToMany(mappedBy: 'contact', targetEntity: TaskNote::class)]
    private Collection $taskNotes;

    public function __construct(Partner $partner, User $createdBy)
    {
        $this->partner = $partner;
        $this->createdBy = $createdBy;
        $this->createdAt = new \DateTimeImmutable();
        $this->posts = new ArrayCollection();
        $this->contactPartnerProducts = new ArrayCollection();
        $this->taskNotes = new ArrayCollection();
    }

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

    public function getFirstName(): ?string
    {
        return $this->firstName;
    }

    public function setFirstName(string $firstName): static
    {
        $this->firstName = $firstName;

        return $this;
    }

    public function getLastName(): ?string
    {
        return $this->lastName;
    }

    public function setLastName(string $lastName): static
    {
        $this->lastName = $lastName;

        return $this;
    }

    public function getPartner(): ?Partner
    {
        return $this->partner;
    }

    public function setPartner(?Partner $partner): static
    {
        $this->partner = $partner;

        return $this;
    }

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

    public function setBirthday(?\DateTimeImmutable $birthday): void
    {
        $this->birthday = $birthday;
    }

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

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

    public function getPosition(): ?string
    {
        return $this->position;
    }

    public function setPosition(?string $position): static
    {
        $this->position = $position;

        return $this;
    }

    public function getPhone(): ?string
    {
        return $this->phone;
    }

    public function setPhone(?string $phone): static
    {
        $this->phone = $phone;

        return $this;
    }

    public function getEmail(): ?string
    {
        return $this->email;
    }

    public function setEmail(?string $email): static
    {
        $this->email = $email;

        return $this;
    }

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

    public function setCreatedBy(?User $createdBy): void
    {
        $this->createdBy = $createdBy;
    }

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

    public function setCreatedAt(\DateTimeImmutable $createdAt): static
    {
        $this->createdAt = $createdAt;

        return $this;
    }

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

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

        return $this;
    }

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

        return $this;
    }

    /**
     * @return Collection<int, ContactPartnerProduct>
     */
    public function getContactPartnerProducts(): Collection
    {
        return $this->contactPartnerProducts;
    }

    public function addContactPartnerProduct(ContactPartnerProduct $contactPartnerProduct): static
    {
        if (!$this->contactPartnerProducts->contains($contactPartnerProduct)) {
            $this->contactPartnerProducts->add($contactPartnerProduct);
            $contactPartnerProduct->setContact($this);
        }

        return $this;
    }

    public function removeContactPartnerProduct(ContactPartnerProduct $contactPartnerProduct): static
    {
        if ($this->contactPartnerProducts->removeElement($contactPartnerProduct)) {
            // set the owning side to null (unless already changed)
            if ($contactPartnerProduct->getContact() === $this) {
                $contactPartnerProduct->setContact(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, TaskNote>
     */
    public function getTaskNotes(): Collection
    {
        return $this->taskNotes;
    }

    public function addTaskNote(TaskNote $taskNote): static
    {
        if (!$this->taskNotes->contains($taskNote)) {
            $this->taskNotes->add($taskNote);
            $taskNote->setContact($this);
        }

        return $this;
    }

    public function removeTaskNote(TaskNote $taskNote): static
    {
        if ($this->taskNotes->removeElement($taskNote)) {
            // set the owning side to null (unless already changed)
            if ($taskNote->getContact() === $this) {
                $taskNote->setContact(null);
            }
        }

        return $this;
    }
}
