<?php

declare(strict_types=1);

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

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;
use Seka\Portal\Modul\Terminy\Entities\Dtos\UdalostDTO;

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

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

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

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

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

    /**
     * @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.aktualizovana')
            ->withUdalost($this->udalost)
            ->withUdalostPovodna($this->udalostPovodna)
            ->withUrlUdalosti($urlUdalosti)
            ->replyTo(config('terminy.podpora.email'));
    }
}
