import { z } from 'zod';

export const systemIdSchema = z.enum(['5e', 'pf2e']);

export const proficiencyRankSchema = z.enum([
  'untrained',
  'trained',
  'expert',
  'master',
  'legendary',
]);

/** A finite integer — rejects NaN and Infinity, which the old app accepted everywhere. */
export const int = z.number().int().finite();
/** A finite number (allows fractions, e.g. CR 1/2). */
export const num = z.number().finite();

export const abilityScoresSchema = z.object({
  str: int,
  dex: int,
  con: int,
  int: int,
  wis: int,
  cha: int,
});

export const hpSchema = z.object({
  current: int,
  max: int.nonnegative(),
  temp: int.nonnegative().default(0),
});

export const conditionSchema = z.object({
  name: z.string().min(1),
  /** stacking value, e.g. PF2e frightened 2 or 5e exhaustion level */
  value: int.positive().optional(),
  /** rounds remaining; undefined = indefinite (used by combat auto-expiry) */
  duration: int.positive().optional(),
});

/** Coins. 5e uses cp/sp/ep/gp/pp; PF2e cp/sp/gp/pp (ep stays 0). */
export const currencySchema = z.object({
  cp: int.nonnegative().default(0),
  sp: int.nonnegative().default(0),
  ep: int.nonnegative().default(0),
  gp: int.nonnegative().default(0),
  pp: int.nonnegative().default(0),
});

export type HitPoints = z.infer<typeof hpSchema>;
export type Condition = z.infer<typeof conditionSchema>;
export type Currency = z.infer<typeof currencySchema>;
