<?php

namespace Modules\MembershipApplication\Emails;

use App\Models\Document;
use App\Notifications\Concerns\BuildsMailMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Storage;
use Modules\MembershipApplication\Entities\MembershipApplication;

class MembershipApplicationFailedNotification extends Notification implements ShouldQueue
{
    use BuildsMailMessage;
    use Queueable;

    public function __construct(
        public MembershipApplication $application,
        public Document $resultLetter,
    ) {}

    /**
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        $this->application->loadMissing('applicant');
        $applicant = $this->application->applicant;

        return $this->mailMessage(
            subject: 'Keputusan Permohonan Keahlian KOPKB - TIDAK LULUS',
            view: 'membershipapplication::emails.failed',
            data: [
                'application' => $this->application,
                'applicant' => $applicant,
            ],
        )->attach(
                Storage::disk(Document::STORAGE_DISK)->path($this->resultLetter->path),
                [
                    'as' => $this->resultLetter->name,
                    'mime' => $this->resultLetter->mime_type,
                ]
            );
    }
}
