<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Terminy\Mail\Udalost;

use Illuminate\Support\Str;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Elceka\Laravel\HashId\Hasher;
use Illuminate\Support\Facades\URL;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Seka\Portal\Modul\Terminy\Entities\Dtos\UdalostDTO;

/**
 * Class ZverejnenaNovaUdalostMail
 *
 * @package Seka\Portal\Modul\Terminy\Mail\Udalost
 */
final class ZverejnenaNovaUdalostMail extends Mailable implements ShouldQueue
{
    use Queueable;
    use SerializesModels;

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

    /**
     * @var \Seka\Portal\Modul\Terminy\Entities\Dtos\UdalostDTO
     */
    public UdalostDTO $udalost;

    /**
     * ZverejnenaNovaUdalostMail constructor.
     *
     * @param \Seka\Portal\Modul\Terminy\Entities\Dtos\UdalostDTO $udalost
     */
    public function __construct(UdalostDTO $udalost)
    {
        $this->udalost = $udalost;
    }

    /**
     * @return mixed
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function build()
    {
        $urlUdalosti = URL::signedRoute(
            'modul.terminy.frontend.udalosti.udalost.show',
            [
                'mtUdalostId' => Hasher::encode($this->udalost->id)
            ]
        );

        return $this
            ->subject(Str::ucfirst($this->udalost->druh->label))
            ->markdown('Terminy::mail.udalost.public.zverejnena')
            ->withUdalost($this->udalost)
            ->withUrlUdalosti($urlUdalosti)
            ->replyTo(config('terminy.podpora.email'));
    }
}
