<?php

namespace App\Entity;

use App\Repository\PushSubscriptionRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: PushSubscriptionRepository::class)]
#[ORM\Index(columns: ['coastal_point_id'], name: 'idx_push_coastal_point')]
class PushSubscription
{
    #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME, unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
    private ?Uuid $id = null;

    #[ORM\Column(type: 'text', unique: true)]
    private string $endpoint;

    #[ORM\Column(type: 'text')]
    private string $authToken;

    #[ORM\Column(type: 'text')]
    private string $p256dhKey;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
    private ?CoastalPoint $coastalPoint = null;

    #[ORM\Column]
    private \DateTimeImmutable $createdAt;

    public function __construct()
    {
        $this->endpoint  = '';
        $this->authToken = '';
        $this->p256dhKey = '';
        $this->createdAt = new \DateTimeImmutable();
    }

    public function getId(): ?Uuid { return $this->id; }
    public function getEndpoint(): string { return $this->endpoint; }
    public function setEndpoint(string $endpoint): static { $this->endpoint = $endpoint; return $this; }
    public function getAuthToken(): string { return $this->authToken; }
    public function setAuthToken(string $authToken): static { $this->authToken = $authToken; return $this; }
    public function getP256dhKey(): string { return $this->p256dhKey; }
    public function setP256dhKey(string $p256dhKey): static { $this->p256dhKey = $p256dhKey; return $this; }
    public function getCoastalPoint(): ?CoastalPoint { return $this->coastalPoint; }
    public function setCoastalPoint(?CoastalPoint $coastalPoint): static { $this->coastalPoint = $coastalPoint; return $this; }
    public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; }
}
