<?php

namespace App\Mail;

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;
use App\Models\Payment;

class PaymentRequestMail extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    public $payment;
    public $isConfirmed;

    /**
     * Create a new message instance.
     */
    public function __construct(Payment $payment, bool $isConfirmed = false)
    {
        $this->payment = $payment;
        $this->isConfirmed = $isConfirmed;
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        $subject = $this->isConfirmed 
            ? 'Payment Confirmed - ' . $this->payment->payment_reference
            : 'Payment Status Update - ' . $this->payment->payment_reference;

        return new Envelope(
            subject: $subject,
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        $view = $this->isConfirmed ? 'emails.payments.confirmed' : 'emails.payments.status';
        
        return new Content(
            view: $view,
            with: [
                'payment' => $this->payment,
                'booking' => $this->payment->booking,
                'package' => $this->payment->booking->package,
                'isConfirmed' => $this->isConfirmed,
            ]
        );
    }

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