import type { DifficultyKey } from "./constants.js";

export type WalletPayload = {
  points: number;
  inventory: {
    hints: number;
    undos: number;
    replays: number;
  };
};

export type WalletRow = {
  points: number;
  hints: number;
  undos: number;
  replays: number;
};

export type RefreshTokenRow = {
  user_id: number;
  token_hash: string;
  expires_at: Date | string;
  revoked_at: Date | string | null;
};

export type ProgressPayload = Record<DifficultyKey, number>;

export type User = {
  id: number;
  email: string;
  displayName: string;
  emailVerified: boolean;
  avatar: string | null;
  accent: string | null;
  title: string | null;
  motto: string | null;
  guest: boolean;
  isAdmin: boolean;
  vipNoAds: boolean;
  vipExpiresAt: Date | string | null;
};

export type UserRecord = User & {
  passwordHash: string | null;
  failedAttempts: number;
  lockedUntil: Date | string | null;
  resetTokenHash: string | null;
  resetTokenExpires: Date | string | null;
  emailVerifiedAt: Date | string | null;
  emailVerifyTokenHash: string | null;
  emailVerifyTokenExpires: Date | string | null;
  bannedAt: Date | string | null;
  banUntil: Date | string | null;
  banReason: string | null;
};

export type AidKind = "hint" | "undo" | "replay";

export type LevelStat = {
  completions: number;
  lastMoves: number;
  lastTime: number;
  bestMoves?: number;
  bestTime?: number;
};

export type RecentRun = {
  difficulty: DifficultyKey;
  levelId: number;
  moves: number;
  time: number;
  completedAt: number;
};

export type StatsState = {
  levels: Record<string, LevelStat>;
  totals: {
    completions: number;
    totalMoves: number;
    totalTime: number;
  };
  recentRuns: RecentRun[];
  tutorialCompleted: boolean;
  badgesUnlocked: string[];
};

export type ArcadeStats = {
  bestScore: number;
  bestLevels: number;
  lastScore: number;
  lastLevels: number;
  lastPlayedAt: number;
};

export type InfiniteStats = {
  bestLevels: number;
  lastLevels: number;
  lastPlayedAt: number;
};

export type DailyProgress = {
  completed: string[];
  monthlyClaims: string[];
};

export type SettingsState = {
  music: boolean;
  sfx: boolean;
  haptics: boolean;
  theme: string;
  animationSpeed: string;
  sfxVolume: number;
  musicVolume: number;
  ballSkin?: string | null;
};

export type UserRow = {
  id: number;
  email: string;
  passwordHash?: string | null;
  failedAttempts?: number | null;
  lockedUntil?: Date | string | null;
  resetTokenHash?: string | null;
  resetTokenExpires?: Date | string | null;
  emailVerified?: number | boolean | null;
  emailVerifiedAt?: Date | string | null;
  emailVerifyTokenHash?: string | null;
  emailVerifyTokenExpires?: Date | string | null;
  displayName?: string | null;
  avatar?: string | null;
  accent?: string | null;
  title?: string | null;
  motto?: string | null;
  guest?: number | boolean;
  isAdmin?: number | boolean;
  vipNoAds?: number | boolean;
  vipExpiresAt?: Date | string | null;
  bannedAt?: Date | string | null;
  banUntil?: Date | string | null;
  banReason?: string | null;
};
