const CLAUDE_SESSION_KEY_PATTERN = /^sk-ant-[A-Za-z0-9_-]+$/;

export function validateClaudeSessionKey(value: string): string | null {
  const key = value.trim();
  if (!key.startsWith("sk-ant-")) {
    return "Session key must start with sk-ant-";
  }
  if (key.length <= 40) {
    return "Session key looks too short. Paste the complete cookie value.";
  }
  if (!CLAUDE_SESSION_KEY_PATTERN.test(key)) {
    return "Session key contains unexpected characters. Check the pasted value.";
  }
  return null;
}

export function isClaudeSessionKeyValid(value: string): boolean {
  return validateClaudeSessionKey(value) === null;
}
