from __future__ import annotations

from codeflash_api.auth.models import (
    CODEFLASH_EMPLOYEE_IDS,
    AuthenticatedUser,
    Subscription,
    is_codeflash_employee,
)


class TestIsCodeflashEmployee:
    """Tests for is_codeflash_employee."""

    def test_known_employee(self) -> None:
        """
        Known GitHub IDs are recognized as employees.
        """
        assert is_codeflash_employee("github|1271289") is True

    def test_unknown_user(self) -> None:
        """
        Arbitrary user IDs are not employees.
        """
        assert is_codeflash_employee("github|999999") is False

    def test_empty_string(self) -> None:
        """
        Empty string is not an employee.
        """
        assert is_codeflash_employee("") is False

    def test_all_ids_present(self) -> None:
        """
        The frozenset contains exactly 7 employee IDs.
        """
        assert 7 == len(CODEFLASH_EMPLOYEE_IDS)


class TestAuthenticatedUser:
    """Tests for AuthenticatedUser attrs class."""

    def test_frozen(self) -> None:
        """
        AuthenticatedUser is immutable.
        """
        user = AuthenticatedUser(
            user_id="u1",
            tier=None,
            api_key_id=1,
            organization_id=None,
            should_log_features=True,
        )
        try:
            user.user_id = "changed"  # type: ignore[misc]
        except AttributeError:
            pass
        else:
            msg = "AuthenticatedUser should be frozen"
            raise AssertionError(msg)


class TestSubscription:
    """Tests for Subscription attrs class."""

    def test_defaults(self) -> None:
        """
        Subscription defaults match FREE tier expectations.
        """
        sub = Subscription(
            id="sub-1",
            user_id="u1",
            plan_type="FREE",
        )

        assert 0 == sub.optimizations_used
        assert 4000 == sub.optimizations_limit
        assert "active" == sub.subscription_status
        assert sub.stripe_customer_id is None
