<?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;

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

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

    /**
     * Informacia ktora sa posiela v notifikacii
     *
     * @var InformaciaDto
     */
    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_pek')
            ->withInformacia($this->informacia)
            ->withUrlInformacie($urlInformacie);
    }
}
