<?php

declare(strict_types=1);

namespace App\Framework\Database\Example;

use App\Framework\Database\Attributes\Entity;
use App\Framework\Database\Attributes\Column;
use App\Framework\Database\IdGenerator;

/**
 * Beispiel-Entity mit auto-generierter ID
 */
#[Entity('users')]
final readonly class User
{
    #[Column(name: 'id', primary: true)]
    public string $id;

    #[Column(name: 'name')]
    public string $name;

    #[Column(name: 'email')]
    public ?string $email;

    public function __construct(
        string $name,
        ?string $email = null,
        ?string $id = null
    ) {
        $this->id = $id ?? IdGenerator::generate();
        $this->name = $name;
        $this->email = $email;
    }

    /**
     * Erstellt eine neue Instanz mit geändertem Namen
     */
    public function withName(string $name): self
    {
        return new self($name, $this->email, $this->id);
    }

    /**
     * Erstellt eine neue Instanz mit geänderter Email
     */
    public function withEmail(?string $email): self
    {
        return new self($this->name, $email, $this->id);
    }
}
