<?php

namespace App\Entity;

use App\Repository\KoboSyncedBookRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

#[ORM\Entity(repositoryClass: KoboSyncedBookRepository::class)]
#[ORM\UniqueConstraint(name: 'kobo_synced_book_unique', columns: ['book_id', 'kobo_device_id'])]
class KoboSyncedBook
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
    private ?\DateTimeImmutable $archived = null;

    public function __construct(#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
        #[Gedmo\Timestampable(on: 'create')]
        private \DateTimeImmutable $created, #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
        #[Gedmo\Timestampable(on: 'update')]
        private ?\DateTimeImmutable $updated, #[ORM\ManyToOne(inversedBy: 'koboSyncedBooks')]
        #[ORM\JoinColumn(nullable: true)]
        private ?KoboDevice $koboDevice, #[ORM\ManyToOne(inversedBy: 'koboSyncedBooks')]
        #[ORM\JoinColumn(nullable: true)]
        private ?Book $book)
    {
        $this->created = new \DateTimeImmutable();
    }

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

    public function getBook(): ?Book
    {
        return $this->book;
    }

    public function setBook(?Book $book): static
    {
        $this->book = $book;

        return $this;
    }

    public function getKoboDevice(): ?KoboDevice
    {
        return $this->koboDevice;
    }

    public function setKoboDevice(?KoboDevice $koboDevice): static
    {
        $this->koboDevice = $koboDevice;

        return $this;
    }

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

    public function setCreated(\DateTimeImmutable $created): static
    {
        $this->created = $created;

        return $this;
    }

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

    public function setUpdated(?\DateTimeImmutable $updated): static
    {
        $this->updated = $updated;

        return $this;
    }

    public function isArchived(): bool
    {
        return $this->archived instanceof \DateTimeInterface;
    }

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

    public function setArchived(?\DateTimeImmutable $removed): void
    {
        $this->archived = $removed;
    }
}
