<?php

namespace App\Mail\Informacia;

use App\Dtos\InformaciaDto;
use Elceka\Laravel\HashId\Hasher;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;

/**
 * Class ZverejnenaInformaciaPrePouzivatelaMail
 */
final class ZverejnenaInformaciaPrePouzivatelaMail extends Mailable implements ShouldQueue
{
    use Queueable;
    use SerializesModels;

    /**
     * @var string
     */
    public $mailer = 'broadcast';

    /**
     * Informacia ktora sa posiela v notifikacii
     */
    private InformaciaDto $informacia;

    /**
     * Konstruktor pre vytvorenie novej notifikacie
     *
     * @param  InformaciaDto  $informacia  Informacia ktora sa posiela v notifikacii
     */
    public function __construct(InformaciaDto $informacia)
    {
        $this->informacia = $informacia;
    }

    /**
     * @return mixed
     *
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function build()
    {
        $urlInformacie = URL::route(
            'portal.informacie.show',
            [
                'informaciaId' => Hasher::encode($this->informacia->id),
            ],
        );

        return $this
            ->subject(Str::ucfirst($this->informacia->titulok))
            ->markdown('mail.informacia.zverejnena_pouzivatel')
            ->withInformacia($this->informacia)
            ->withUrlInformacie($urlInformacie);
    }
}
