import uuid
from datetime import datetime
from zoneinfo import ZoneInfo

from freezegun import freeze_time
from src.domain.entities.client_api_key import ClientApiKey, ClientApiKeyAlgorithm, ClientApiKeyStatus


class TestClientApiKey:
    @freeze_time("2024-01-01 12:00:00", tz_offset=-9)  # Asia/Tokyo
    def test_mark_as_rotated(self):
        """ClientApiKey の mark_as_rotated で正しくフィールドが更新されることを確認する"""
        client_api_key = ClientApiKey(
            id="key_id",
            client_id=uuid.uuid4(),
            hashed_secret="hashed secret",  # noqa: S106
            algorithm=ClientApiKeyAlgorithm.SHA256,
            status=ClientApiKeyStatus.ACTIVE,
            rotated_at=None,
            expires_at=None,
        )
        expected_rotated_at = datetime(year=2024, month=1, day=1, hour=12, minute=0, tzinfo=ZoneInfo("Asia/Tokyo"))
        expected_expires_at = datetime(year=2024, month=1, day=8, hour=12, minute=0, tzinfo=ZoneInfo("Asia/Tokyo"))

        rotated_key = client_api_key.mark_as_rotated()

        assert rotated_key.status == ClientApiKeyStatus.DEPRECATED
        assert rotated_key.rotated_at == expected_rotated_at
        assert rotated_key.expires_at == expected_expires_at
