"""EmailConfig 单元测试."""

from __future__ import annotations

import pytest
from domain.auth.email_service import EmailConfig


class TestEmailConfigDefaults:
    """默认值测试."""

    def test_default_values(self):
        config = EmailConfig()
        assert config.smtp_host == "smtp.gmail.com"
        assert config.smtp_port == 587
        assert config.smtp_user == ""
        assert config.smtp_password == ""
        assert config.from_email == ""
        assert config.from_name == "小虾 SaaS"
        assert config.use_tls is True

    def test_custom_construction(self):
        config = EmailConfig(
            smtp_host="smtp.example.com",
            smtp_port=465,
            smtp_user="user@example.com",
            smtp_password="secret",
            from_email="no-reply@example.com",
            from_name="Example App",
            use_tls=False,
        )
        assert config.smtp_host == "smtp.example.com"
        assert config.smtp_port == 465
        assert config.smtp_user == "user@example.com"
        assert config.smtp_password == "secret"
        assert config.from_email == "no-reply@example.com"
        assert config.from_name == "Example App"
        assert config.use_tls is False

    def test_is_dataclass(self):
        # 可重复创建相同配置
        c1 = EmailConfig(smtp_host="h.com", smtp_port=25)
        c2 = EmailConfig(smtp_host="h.com", smtp_port=25)
        assert c1 == c2


class TestEmailConfigEquality:
    """相等性测试."""

    def test_equal_same_values(self):
        c1 = EmailConfig()
        c2 = EmailConfig()
        assert c1 == c2

    def test_not_equal_different_host(self):
        c1 = EmailConfig(smtp_host="a.com")
        c2 = EmailConfig(smtp_host="b.com")
        assert c1 != c2

    def test_not_equal_different_port(self):
        c1 = EmailConfig(smtp_port=587)
        c2 = EmailConfig(smtp_port=465)
        assert c1 != c2
