<?php

namespace Slovocast\Domain\Model;

class User
{
    public function __construct(
        private readonly ?int $id,
        private string $email,
        private string $password,
        private string $name
    ) {
        $this->email = $email;
        $this->password = $password;
        $this->name;
    }

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

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

    public function getName(): string
    {
        return $this->name;
    }

    /**
     * If the `id` property exists, we can assume this entity already exists.
     *
     * @return bool
     */
    public function isNew(): bool
    {
        return (bool) $this->id;
    }

    /**
     * @param string[] $props Properties of the User model
     * @return User
     */
    public static function fromArray(array $props): User
    {
        return new self(
            $props['id'] ?? null,
            $props['email'],
            $props['password'],
            $props['name']
        );
    }
}
