<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\User\Model;

use CpCreation\VitiCore\Behavior\HasTimestamp;
use CpCreation\VitiCore\Behavior\Impl\Timestamp;
use CpCreation\VitiCore\Product\Model\ProductPriceGroup;
use CpCreation\VitiCore\User\Repository\ImportedClientGroupRepository;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

#[ORM\Entity(repositoryClass: ImportedClientGroupRepository::class)]
#[ORM\Table(name: 'user_imported_client_group')]
#[ORM\UniqueConstraint(name: 'uniq_imported_client_group_email', columns: ['email'])]
#[ORM\HasLifecycleCallbacks]
class ImportedClientGroup implements HasTimestamp
{
    use Timestamp;

    #[ORM\Id]
    #[ORM\Column(type: 'uuid')]
    #[ORM\GeneratedValue(strategy: 'NONE')]
    private UuidInterface $id;

    #[ORM\Column(type: 'string', length: 60)]
    private string $email;

    #[ORM\ManyToOne(targetEntity: ProductPriceGroup::class)]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private ProductPriceGroup $group;

    #[ORM\Column(type: 'boolean', options: ['default' => true])]
    private bool $applyOnRegistration = true;

    public function __construct(string $email, ProductPriceGroup $group)
    {
        $this->id = Uuid::uuid4();
        $this->email = $email;
        $this->group = $group;
    }

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

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

    public function setEmail(string $email): void
    {
        $this->email = $email;
    }

    public function getGroup(): ProductPriceGroup
    {
        return $this->group;
    }

    public function setGroup(ProductPriceGroup $group): void
    {
        $this->group = $group;
    }

    public function shouldApplyOnRegistration(): bool
    {
        return $this->applyOnRegistration;
    }

    public function setApplyOnRegistration(bool $applyOnRegistration): void
    {
        $this->applyOnRegistration = $applyOnRegistration;
    }
}
