from typing import Annotated

from pydantic import AfterValidator, BaseModel, EmailStr

from service.core.exceptions import InvalidEmail
from service.utils.validation import validate_email


def email_validation(email: EmailStr) -> str:
    try:
        validated = validate_email(email)
    except InvalidEmail as e:
        raise AssertionError(str(e))
    return validated.normalized


ValidEmail = Annotated[EmailStr, AfterValidator(email_validation)]


class Message(BaseModel):
    message: str
