<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require_once __DIR__ . '/../vendor/autoload.php'; // Adjust path as needed

class Mailer {
    private $mail;

    public function __construct() {
        $this->mail = new PHPMailer(true);
        $this->setup();
    }

    private function setup() {
        $this->mail->isSMTP();
        $this->mail->Host       = 'mail.annie.com.ng';
        $this->mail->SMTPAuth   = true;
        $this->mail->Username   = 'app@annie.com.ng';
        $this->mail->Password   = 'Q%y?7[GTEaGrDURQ';
        $this->mail->SMTPSecure = 'tls';
        $this->mail->Port       = 587;
        $this->mail->setFrom('app@annie.com.ng', 'Annie');
        $this->mail->isHTML(true);
    }

    public function send($to, $subject, $message) {
        try {
            $this->mail->clearAddresses();
            $this->mail->addAddress($to);
            $this->mail->Subject = $subject;
            $this->mail->Body    = $message;
            $this->mail->AltBody = strip_tags($message);

            $this->mail->send();
            return ['status' => 'success', 'message' => 'Mail sent successfully'];
        } catch (Exception $e) {
            return ['status' => 'error', 'message' => $this->mail->ErrorInfo];
        }
    }
}
