<?php

namespace App\Mail;

use AllowDynamicProperties;
use App;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class PreApplicationMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     */
    public function __construct(protected App\Models\PreApplications $pa, protected string $lang = 'de')
    {
        //
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: __('mail.preapplication.subject'),
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        App::setLocale($this->lang);
        return new Content(
            view: 'mail.preapplication',
            with: ['pa' => $this->pa],
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, Attachment>
     */
    public function attachments(): array
    {
        $lang = match (App::getLocale()) {
            'de' => 'dk',
            'en' => 'ek',
            default => 'dk',
        };
        return [
            Attachment::fromPath(public_path('Dokumente/c3gov_fb5' . $lang . '.pdf'))
            ->withMime('application/pdf'),
        ];
    }
}
