<?php

namespace domain\User\User;

use domain\Producer\Producer\Producer;
use domain\Ticket\Ticket\Ticket;
use domain\_\AbstractNotifier;
use domain\_\ManagerInterface;

class UserNotifier extends AbstractNotifier implements ManagerInterface
{
    protected UserSolver $userSolver;

    public function loadDependencies(): void
    {
        parent::loadDependencies();
        $this->userSolver = $this->loadService(UserSolver::class);
    }

    public function sendEmailSignup(User $user, Producer $producer)
    {
        $this->mailer->sendFromSite(
            'Inscription',
            'signup',
            [
                'user' => $user,
                'producer' => $producer
            ],
            $user->email
        );
    }

    /**
     * Envoie un email de bienvenue à l'utilisateur lors de son inscription
     * via le backend du site.
     */
    public function sendMailWelcome(User $user, string $password): void
    {
        if (strlen($user->email)) {
            $producer = $this->getProducerContext();
            $this->mailer->sendFromProducer(
                'Inscription',
                'createUserAdmin',
                [
                    'user' => $user,
                    'producer' => $producer,
                    'password' => $password
                ],
                $user->email,
                $producer
            );
        }
    }

    public function sendMailNewPassword(User $user, string $password)
    {
        $producer = $this->getProducerContext();
        \Yii::$app->mailerService->sendFromProducer(
            'Nouveau mot de passe',
            'newPasswordUserAdmin',
            [
                'user' => $user,
                'producer' => $producer,
                'password' => $password,
            ],
            $user->email,
            $producer
        );
    }
}