<?php

namespace Entity;

use Doctrine\ORM\Mapping as ORM;
use Entity\Kampagne;
use Entity\User;

#[ORM\Entity]
#[ORM\Table(name: 'reloadsperre')]
#[ORM\Index(name: 'idx_kampagne_user', columns: ['kampagne_id', 'user_id'])]
#[ORM\Index(name: 'idx_reload_bis', columns: ['reload_bis'])]
#[ORM\HasLifecycleCallbacks]
class Reloadsperre
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: Kampagne::class)]
    #[ORM\JoinColumn(name: 'kampagne_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')]
    private Kampagne $kampagne;

    #[ORM\ManyToOne(targetEntity: User::class)]
    #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
    private User $user;

    #[ORM\Column(type: 'datetime')]
    private \DateTimeInterface $reload_bis;

    #[ORM\Column(type: 'integer', options: ['unsigned' => true])]
    private int $ip;

    #[ORM\Column(type: 'datetime')]
    private \DateTimeInterface $dateCreated;

    #[ORM\PrePersist]
    public function setDateCreatedValue(): void
    {
        $this->dateCreated = new \DateTime();
    }

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

    public function getKampagne(): Kampagne
    {
        return $this->kampagne;
    }

    public function setKampagne(Kampagne $kampagne): self
    {
        $this->kampagne = $kampagne;
        return $this;
    }

    public function getUser(): User
    {
        return $this->user;
    }

    public function setUser(User $user): self
    {
        $this->user = $user;
        return $this;
    }

    public function getReloadBis(): \DateTimeInterface
    {
        return $this->reload_bis;
    }

    public function setReloadBis(\DateTimeInterface $reload_bis): self
    {
        $this->reload_bis = $reload_bis;
        return $this;
    }

    public function getIp(): string
    {
        return long2ip($this->ip);
    }

    public function setIp(string $ip): self
    {
        $this->ip = ip2long($ip);
        return $this;
    }

    public function getDateCreated(): \DateTimeInterface
    {
        return $this->dateCreated;
    }
}
