<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\notifiers;

use apexl\Config\ConfigurationInterface;
use apexl\Io\modules\email\services\TemplateService;
use apexl\Io\modules\notifier\interfaces\emailNotifierDriverInterface;
use apexl\Io\modules\notifier\notifiers\emailNotifier;
use apexl\Io\modules\user\entities\userEntity;
use apexl\Io\modules\user\interfaces\NewUserNotifierInterface;
use Exception;

final class NewUserEmailNotifier extends emailNotifier implements NewUserNotifierInterface
{
    public userEntity $user;

    public function __construct(
        private readonly TemplateService $templateService,
        private readonly ConfigurationInterface $config,
        emailNotifierDriverInterface $driver,
    ) {
        parent::__construct($driver);
    }

    protected function to(): string
    {
        assert(isset($this->user));

        return $this->user->email;
    }

    protected function subject(): string
    {
        return 'Welcome to the Tile Designer!';
    }

    /**
     * @throws Exception
     */
    protected function body(): string
    {
        return $this->templateService->fetch('new_user', [
            'name' => $this->user->first_name,
            'domain' => $this->config->get('app.site.frontend_domain'),
        ]);
    }
}
