from __future__ import annotations

from pathlib import Path

from shared_codex_state import SharedCodexState


class SharedClaudeState(SharedCodexState):
    def __init__(self, shared_home: Path, accounts_dir: Path) -> None:
        super().__init__(legacy_codex_home=shared_home, accounts_dir=accounts_dir)

    def sync_all_shared_links(self) -> None:
        if not self.accounts_dir.exists():
            return
        for account_dir in sorted(self.accounts_dir.iterdir()):
            if account_dir.name.startswith("."):
                continue
            account_home = account_dir / "CLAUDE_HOME"
            if account_home.is_dir():
                self.sync_shared_links(account_home)

    @staticmethod
    def _is_credential_name(name: str) -> bool:
        return (
            name in {
                ".claude-auth.lock",
                ".claude.json",
                ".last-cleanup",
                ".last-update-result.json",
                "account_identity.json",
                "backups",
                "claude.json",
                "daemon",
                "daemon.status.json",
                "rate-limits-cache.json",
                "usage-backoff.json",
            }
            or name.startswith(".credentials.json")
            or name.startswith("rate-limits-cache.json.")
        )
