Coverage for postrfp/mail/protocol.py: 100%
4 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-22 21:34 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-22 21:34 +0000
1"""
2Mailer Protocol Interface
4Defines the contract that all mailer implementations must follow.
5This protocol can be implemented by a module or a class.
6This replaces the current implicit duck typing with explicit type safety.
7"""
9from typing import Protocol, runtime_checkable, Union, TYPE_CHECKING
11if TYPE_CHECKING:
12 from postrfp.mail.schemas import TemplateEmailModel, SimpleEmailModel
15@runtime_checkable
16class MailerProtocol(Protocol):
17 """
18 Protocol defining the interface for email delivery implementations.
20 All mailer implementations (stub, postmark, etc.) must implement this interface.
21 This provides type safety while allowing different implementation strategies.
22 """
24 def send_email(self, model: Union["TemplateEmailModel", "SimpleEmailModel"]) -> str:
25 """
26 Send an email using the provided Pydantic model.
28 Args:
29 model: Email data Pydantic model - either TemplateEmailModel for event
30 notifications or SimpleEmailModel for basic messages.
32 Returns:
33 str: Message ID from the email provider (UUID for stub, MessageID from Postmark)
35 Raises:
36 Exception: If email sending fails for any reason
37 """
38 ...