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

/** 全项目统一：后台账号、代理账号、彩票端玩家密码最短长度 */
export const PASSWORD_MIN_LENGTH = 6;
export const ADMIN_PASSWORD_MIN_LENGTH = PASSWORD_MIN_LENGTH;
export const NATIVE_PLAYER_PASSWORD_MIN_LENGTH = PASSWORD_MIN_LENGTH;

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

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

  return null;
}

export function validateAdminPassword(
  value: string,
  minLength: number = ADMIN_PASSWORD_MIN_LENGTH,
): PasswordValidationIssue | null {
  if (value === "") {
    return "empty";
  }
  if (value.length < minLength) {
    return "too_short";
  }

  return null;
}

export function validateNativePlayerUsername(value: string): AccountValidationIssue | null {
  return validateAdminLoginAccount(value);
}

export function validateNativePlayerPassword(value: string): PasswordValidationIssue | null {
  return validateAdminPassword(value, NATIVE_PLAYER_PASSWORD_MIN_LENGTH);
}
