<?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\Booking;
use App\Models\Package;

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

    public $booking;
    public $package;
    public $isAdmin;

    /**
     * Create a new message instance.
     */
    public function __construct(Booking $booking, Package $package, bool $isAdmin = false)
    {
        $this->booking = $booking;
        $this->package = $package;
        $this->isAdmin = $isAdmin;
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        $subject = $this->isAdmin 
            ? 'New Booking Received - ' . $this->booking->booking_reference
            : 'Booking Confirmation - ' . $this->booking->booking_reference;

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

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        $view = $this->isAdmin ? 'emails.bookings.admin-notification' : 'emails.bookings.confirmation';
        
        return new Content(
            view: $view,
            with: [
                'booking' => $this->booking,
                'package' => $this->package,
                'isAdmin' => $this->isAdmin,
            ]
        );
    }

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