<?php

declare(strict_types=1);

namespace Apexl\Io\User\Notifiers;

use Apexl\Io\Notifier\Interfaces\EmailNotifierDriverInterface;
use Apexl\Io\Notifier\Notifiers\EmailNotifier;
use Apexl\Io\Services\HttpPaths;
use Apexl\Io\Template\Services\TemplateService;
use Apexl\Io\User\Entities\UserEntity;
use Apexl\Io\User\Interfaces\NewUserNotifierInterface;
use Exception;

final class NewUserEmailNotifier extends EmailNotifier implements NewUserNotifierInterface
{
    public UserEntity $user;

    public function __construct(
        private readonly HttpPaths $httpPaths,
        private readonly TemplateService $templateService,
        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->template('email/new_user', [
            'name' => $this->user->first_name,
            'domain' => $this->httpPaths->frontendUrl(),
        ]);
    }
}
