<?php

namespace AutoAdmin\Bundle\Seo\Entity;

use AutoAdmin\Bundle\Content\Entity\AbstractUntranslated;
use AutoAdmin\Bundle\Content\Model\UpdatedAtOptOutInterface;
use AutoAdmin\Bundle\Seo\Repository\RedirectRepository;
use Doctrine\DBAL\Types\Types;
use AutoAdmin\Bundle\Content\Entity\Interfaces\RedirectInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\Response;

#[ORM\Entity(repositoryClass: RedirectRepository::class)]
#[UniqueEntity(['origin', 'site'])]
class Redirect extends AbstractUntranslated implements RedirectInterface, UpdatedAtOptOutInterface
{
    public const REDIRECT_301 = Response::HTTP_MOVED_PERMANENTLY;
    public const REDIRECT_302 = Response::HTTP_FOUND;

    #[ORM\Column(name: 'origin', type: Types::STRING, length: 255)]
    protected string $origin;

    #[ORM\Column(name: 'destination', type: Types::STRING, length: 255)]
    protected string $destination;

    #[ORM\Column(name: 'type', type: Types::INTEGER)]
    protected int $type;

    #[ORM\Column(name: 'counter', type: Types::INTEGER)]
    protected int $counter = 0;

    #[ORM\Column(name: 'root_redirect', type: Types::BOOLEAN)]
    protected bool $rootRedirect = false;

    public function getOrigin(): ?string
    {
        return $this->origin;
    }

    public function setOrigin(?string $origin): self
    {
        $this->origin = $origin;

        return $this;
    }

    public function getDestination(): ?string
    {
        return $this->destination;
    }

    public function setDestination(?string $destination): self
    {
        $this->destination = $destination;

        return $this;
    }

    public function getType(): ?int
    {
        return $this->type;
    }

    public function setType(?int $type): self
    {
        $this->type = $type;

        return $this;
    }

    public function getCounter(): ?int
    {
        return $this->counter;
    }

    public function setCounter(?int $counter): self
    {
        $this->counter = $counter;

        return $this;
    }

    public function isRootRedirect(): bool
    {
        return $this->rootRedirect;
    }

    public function setRootRedirect(bool $rootRedirect): self
    {
        $this->rootRedirect = $rootRedirect;
        return $this;
    }
}
