from flask import current_app
from flask_mail import Message
 
from app.config.settings import Config


class MailService:
    @staticmethod
    def send_email(subject, recipient, message, attachment=None, html=False): 
        try:
            mail = current_app.extensions['mail']
            msg = Message(
                subject, 
                sender=Config.MAIL_DEFAULT_SENDER, 
                recipients=[recipient]
            )
            if html:
                msg.html = message
            else:
                msg.body = message
            # if attachment:
            #     with app.open_resource(attachment) as fp:
            #         msg.attach(attachment, 'application/octect-stream', fp.read())

            mail.send(msg)
            return True
        except Exception as e:
            print(f"Failed to send email: {str(e)}")
            return False
