<?php

namespace domain\Opinion;

use domain\User\User\User;
use domain\User\User\UserSolver;
use domain\_\AbstractManager;

class OpinionManager extends AbstractManager
{
    protected UserSolver $userSolver;

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

    public function sendOpinionEmailAdmin($opinionFormModel, User $userCurrent = null)
    {
        \Yii::$app->mailerService->sendAdmin(
            'Nouvel avis',
            'newOpinionAdmin',
            [
                'username' => $userCurrent ? $this->userSolver->getUsername($userCurrent) : $opinionFormModel->name,
                'message' => $opinionFormModel->message,
            ],
            $userCurrent ? $userCurrent->email : $opinionFormModel->email
        );
    }
}