<?php

namespace kernel\app_modules\user_stage\notification_messages;

use kernel\app_modules\user_stage\models\User;
use kernel\app_modules\user_stage\models\UserStage;
use kernel\CgView;
use kernel\modules\notification\contracts\NotificationMessage;
use kernel\modules\user\service\UserService;

class UserNewStageNotification extends NotificationMessage
{
    protected UserStage $userStage;
    protected User $user;
    protected CgView $cgView;

    public function __construct(UserStage $userStage, User $user)
    {
        $this->cgView = new CgView();
        $this->cgView->viewPath = ROOT_DIR . $_ENV['EMAIL_VIEWS_PATH'];
        $this->userStage = $userStage;
        $this->user = $user;
        $this->channels = ['email'];
    }

    public function getMessage(): string
    {
        return $this->cgView->fetch('user_new_stage.php', [
            'user' => $this->user->username,
            'stage' => $this->userStage->title,
            'url' => $_ENV['APP_URL'],
        ]);
    }

    public function getSubject(): string
    {
        return "Вам открыт новый этап {$this->userStage->title}";
    }

    public function toArray(): array
    {
        return array_merge(parent::toArray(), [
            'stage_id' => $this->userStage->id,
            'stage_title' => $this->userStage->title
        ]);
    }
}