<?php

declare(strict_types=1);

namespace PhpList\Core\Domain\Subscription\Model;

use Doctrine\ORM\Mapping as ORM;
use PhpList\Core\Domain\Common\Model\Interfaces\DomainModel;
use PhpList\Core\Domain\Subscription\Repository\SubscriberAttributeValueRepository;

#[ORM\Entity(repositoryClass: SubscriberAttributeValueRepository::class)]
#[ORM\Table(name: 'user_user_attribute')]
#[ORM\Index(name: 'phplist_user_user_attribute_attindex', columns: ['attributeid'])]
#[ORM\Index(name: 'phplist_user_user_attribute_attuserid', columns: ['userid', 'attributeid'])]
#[ORM\Index(name: 'phplist_user_user_attribute_userindex', columns: ['userid'])]
class SubscriberAttributeValue implements DomainModel
{
    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: SubscriberAttributeDefinition::class)]
    #[ORM\JoinColumn(name: 'attributeid', referencedColumnName: 'id', onDelete: 'CASCADE')]
    private SubscriberAttributeDefinition $attributeDefinition;

    #[ORM\Id]
    #[ORM\ManyToOne(targetEntity: Subscriber::class, inversedBy: 'attributes')]
    #[ORM\JoinColumn(name: 'userid', referencedColumnName: 'id', onDelete: 'CASCADE')]
    private Subscriber $subscriber;

    #[ORM\Column(name: 'value', type: 'text', nullable: true)]
    private ?string $value = null;

    public function __construct(SubscriberAttributeDefinition $attributeDefinition, Subscriber $subscriber)
    {
        $this->attributeDefinition = $attributeDefinition;
        $this->subscriber = $subscriber;
    }

    public function getAttributeDefinition(): SubscriberAttributeDefinition
    {
        return $this->attributeDefinition;
    }

    public function getSubscriber(): Subscriber
    {
        return $this->subscriber;
    }

    public function getValue(): ?string
    {
        return $this->value;
    }

    public function setValue(?string $value): self
    {
        $this->value = $value;
        return $this;
    }
}
