<?php

namespace App\Notifications\SearchProfiles;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Lang;

class SearchProfileUpdateEmail extends Notification implements ShouldQueue
{
    use Queueable;

    protected $searchProfile;
    protected $competitions;

    public function __construct($searchProfile, $competitions)
    {
        $this->searchProfile = $searchProfile;
        $this->competitions = $competitions;
    }

    /**
     * Get the notification's channels.
     *
     * @param  mixed  $notifiable
     * @return array|string
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Build the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $subject = Lang::get('email.search_profile_update_subject') . ' - ' . $this->searchProfile->name;
        return (new MailMessage)->view(
            'emails.search-profiles.update', [
                'searchProfileName' => $this->searchProfile->name,
                'firstName' => $this->searchProfile->user->first_name,
                'lastName' => $this->searchProfile->user->last_name,
                'competitions' => $this->competitions,
                'subject' => $subject,
                'myWaLink' => config('app.frontend_url') . '/dashboard',
                'frontendUrl' => config('app.frontend_url'),
            ]
        )->subject($subject);
    }
}
