<?php

// SPDX-FileCopyrightText: 2023 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later

namespace Icinga\Module\Notifications\Widget\Calendar;

use InvalidArgumentException;
use ipl\Html\ValidHtml;
use ipl\Web\Widget\Icon;

/**
 * An attendee of a calendar entry
 */
class Attendee
{
    protected string $name;

    protected string|ValidHtml $icon = 'user';

    public function __construct(string $name)
    {
        $this->name = $name;
    }

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

    public function setIcon($icon): static
    {
        if ($icon === null) {
            throw new InvalidArgumentException('Cannot unset icon');
        }

        $this->icon = $icon;

        return $this;
    }

    public function getIcon(): ValidHtml
    {
        if (is_string($this->icon)) {
            $icon = new Icon($this->icon);
        } else {
            $icon = $this->icon;
        }

        return $icon;
    }
}
