<?php

namespace App\Services\Providers;

use App\Models\Appointment;
use Illuminate\Support\Facades\Mail;

class EmailProvider
{
    public function sendAppointmentReminder(string $email, Appointment $appointment): void
    {
        $appointment->loadMissing(['patient', 'doctor.user', 'location']);

        $subject = "Appointment reminder: {$appointment->appointment_code}";
        $message = implode("\n", [
            "Hello {$appointment->patient->name},",
            '',
            'This is a reminder for your Smart Clinic appointment.',
            "Doctor: {$appointment->doctor->user->name}",
            "Location: {$appointment->location->name}",
            "Time: {$appointment->scheduled_start_at->toDateTimeString()} UTC",
            "Appointment: {$appointment->appointment_code}",
        ]);

        Mail::raw($message, function ($mail) use ($email, $subject) {
            $mail->to($email)->subject($subject);
        });
    }
}
