/** 彩票端登录账号：字母、数字、点、下划线、连字符。 */
export const PLAYER_ACCOUNT_PATTERN = /^[a-zA-Z0-9._-]+$/;

export const PLAYER_PASSWORD_MIN_LENGTH = 6;

export type AccountValidationIssue = "empty" | "invalid_charset";
export type PasswordValidationIssue = "empty" | "too_short";

export function validatePlayerLoginUsername(value: string): AccountValidationIssue | null {
  const trimmed = value.trim();
  if (trimmed === "") {
    return "empty";
  }
  if (!PLAYER_ACCOUNT_PATTERN.test(trimmed)) {
    return "invalid_charset";
  }

  return null;
}

export function validatePlayerLoginPassword(value: string): PasswordValidationIssue | null {
  if (value === "") {
    return "empty";
  }
  if (value.length < PLAYER_PASSWORD_MIN_LENGTH) {
    return "too_short";
  }

  return null;
}
