<?php

namespace App\Entity;

use App\Repository\ContactPartnerProductRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ContactPartnerProductRepository::class)]
#[ORM\UniqueConstraint(name: "unique_contact_partner_product", columns: ["contact_id", "partner_product_id"])]
class ContactPartnerProduct
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(inversedBy: 'contactPartnerProducts')]
    #[ORM\JoinColumn(nullable: false, onDelete: "CASCADE")]
    private ?Contact $contact = null;

    #[ORM\ManyToOne(inversedBy: 'contactPartnerProducts')]
    #[ORM\JoinColumn(nullable: false, onDelete: "CASCADE")]
    private ?PartnerProduct $partnerProduct = null;

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

    public function __construct(Contact $contact, PartnerProduct $partnerProduct)
    {
        if ($contact->getPartner()?->getId() !== $partnerProduct->getPartner()?->getId()) {
            throw new \Exception('Contact Partner and ProductPartner Partner do not match!');
        }

        $this->contact = $contact;
        $this->partnerProduct = $partnerProduct;

        $this->createdAt = new \DateTimeImmutable();
    }

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

    public function getContact(): ?Contact
    {
        return $this->contact;
    }

    public function setContact(?Contact $contact): static
    {
        $this->contact = $contact;

        return $this;
    }

    public function getPartnerProduct(): ?PartnerProduct
    {
        return $this->partnerProduct;
    }

    public function setPartnerProduct(?PartnerProduct $partnerProduct): static
    {
        $this->partnerProduct = $partnerProduct;

        return $this;
    }

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

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

        return $this;
    }
}
