import type { Proficiency } from './types';

/** Levels at which a skill-increase step occurs (PF2e CRB). */
export const SKILL_INCREASE_LEVELS: readonly number[] = [3, 5, 7, 9, 11, 13, 15, 17, 19];

/**
 * Minimum character level required to advance a skill from `currentRank`.
 * UNTRAINED → TRAINED is unrestricted (any level >= 1 with a skill-increase step).
 * LEGENDARY is `null` because it is the maximum rank — no further increases possible.
 */
const SKILL_RANK_LEVEL_REQUIREMENTS: Record<Proficiency, number | null> = {
  UNTRAINED: 1, // → TRAINED
  TRAINED: 3, // → EXPERT (PF2e CRB)
  EXPERT: 7, // → MASTER
  MASTER: 15, // → LEGENDARY
  LEGENDARY: null, // already maxed
};

/**
 * PF2e skill-increase cap rule (LVL-06).
 * Returns true if a character at `characterLevel` may advance a skill that is
 * currently at `currentRank` to the next rank.
 */
export function canIncreaseSkill(
  currentRank: Proficiency,
  characterLevel: number,
): boolean {
  const required = SKILL_RANK_LEVEL_REQUIREMENTS[currentRank];
  if (required === null) return false;
  return characterLevel >= required;
}
