<?php
declare(strict_types=1);

namespace App\Mailer;

use App\Model\Entity\Booking;
use App\Model\Entity\ContactMessage;
use Cake\Mailer\Mailer;

class ContactMailer extends Mailer
{
    public static string $name = 'Contact';

    /**
     * Confirmation email sent back to the enquirer.
     */
    public function enquiryConfirmation(ContactMessage $message): self
    {
        $this
            ->setEmailFormat('both')
            ->setTo($message->email, $message->full_name)
            ->setFrom(['hello@candlecraft.local' => 'CandleCraft Academy'])
            ->setSubject('We received your enquiry · CandleCraft Academy')
            ->setViewVars([
                'message' => $message,
                'fullName' => $message->full_name,
            ])
            ->viewBuilder()
            ->setTemplate('enquiry_confirmation');

        return $this;
    }

    /**
     * Reply from admin to an enquirer.
     */
    public function enquiryReply(ContactMessage $message, string $bodyText, string $subjectLine): self
    {
        $this
            ->setEmailFormat('both')
            ->setTo($message->email, $message->full_name)
            ->setFrom(['hello@candlecraft.local' => 'CandleCraft Academy'])
            ->setSubject($subjectLine)
            ->setViewVars([
                'message' => $message,
                'bodyText' => $bodyText,
            ])
            ->viewBuilder()
            ->setTemplate('enquiry_reply');

        return $this;
    }

    /**
     * Booking confirmation email after successful payment.
     */
    public function bookingConfirmation(Booking $booking): self
    {
        $this
            ->setEmailFormat('both')
            ->setTo($booking->customer_email, $booking->customer_name)
            ->setFrom(['hello@candlecraft.local' => 'CandleCraft Academy'])
            ->setSubject('Your class is booked · CandleCraft Academy')
            ->setViewVars([
                'booking' => $booking,
            ])
            ->viewBuilder()
            ->setTemplate('booking_confirmation');

        return $this;
    }
}
