<?php

namespace App\Mail;

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

class WithdrawalEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $custom_subject;
    public $custom_message;

    public $withdrawal;

    /**
     * Create a new message instance.
     */
    public function __construct($custom_subject, $custom_message, $withdrawal)
    {
        $this->custom_subject = $custom_subject;
        $this->custom_message = $custom_message;
        $this->withdrawal = $withdrawal;
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: __($this->custom_subject),
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        // Dynamically resolve view based on active template
        $template = config('site.template');
        $view = "templates.{$template}.mail.withdrawal-email";

        return new Content(
            markdown: $view,
            with: [
                'withdrawal' => $this->withdrawal,
                'custom_message' => $this->custom_message,
                'custom_subject' => $this->custom_subject,
            ],
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}
