<?php

namespace Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: 'Repository\UserRepository')]
#[ORM\Table(name: 'users')]
class User
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private int $id;

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

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

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

    #[ORM\Column(type: 'string', columnDefinition: "ENUM('user', 'admin', 'werbenetzwerk')")]
    private string $rolle = 'user';

    #[ORM\ManyToOne(targetEntity: Werbenetzwerk::class)]
    #[ORM\JoinColumn(name: 'werbenetzwerk_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
    private ?Werbenetzwerk $werbenetzwerk = null;

    #[ORM\Column(type: 'datetime')]
    private \DateTime $createdAt;

    public function __construct()
    {
        $this->createdAt = new \DateTime();
    }

    // Getter und Setter
    public function getId(): int
    {
        return $this->id;
    }

    public function getUsername(): string
    {
        return $this->username;
    }

    public function setUsername(string $username): self
    {
        $this->username = $username;
        return $this;
    }

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

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

    public function getPassword(): string
    {
        return $this->password;
    }

    public function setPassword(string $password): self
    {
        $this->password = $password;
        return $this;
    }

    public function getCreatedAt(): \DateTime
    {
        return $this->createdAt;
    }

    public function setCreatedAt(\DateTime $createdAt): self
    {
        $this->createdAt = $createdAt;
        return $this;
    }

    public function getRolle(): string
    {
        return $this->rolle;
    }

    public function setRolle(string $rolle): self
    {
        if (!in_array($rolle, ['user', 'admin', 'werbenetzwerk'])) {
            throw new \InvalidArgumentException('Rolle muss "user", "admin" oder "werbenetzwerk" sein');
        }
        $this->rolle = $rolle;
        return $this;
    }

    public function isAdmin(): bool
    {
        return $this->rolle === 'admin';
    }

    public function isWerbenetzwerk(): bool
    {
        return $this->rolle === 'werbenetzwerk';
    }

    public function getWerbenetzwerk(): ?Werbenetzwerk
    {
        return $this->werbenetzwerk;
    }

    public function setWerbenetzwerk(?Werbenetzwerk $werbenetzwerk): self
    {
        $this->werbenetzwerk = $werbenetzwerk;
        return $this;
    }
}
