/** Shared content + domain types (safe to import from client or server). */

export type AgeGroup = '3-5' | '6-8' | '9-11' | '12-14';
export type AgeBand = AgeGroup;

export interface AgeBandMeta {
  id: AgeBand;
  label: string; // Bangla display, e.g. "৩-৫ বছর"
  blurb: string; // one-line description
  emoji: string;
  /** young bands auto-read content aloud */
  autoRead: boolean;
}

export const AGE_BANDS: AgeBandMeta[] = [
  { id: '3-5', label: '৩-৫ বছর', blurb: 'একদম ছোটদের জন্য, ছবি ও শব্দ', emoji: '🧸', autoRead: true },
  { id: '6-8', label: '৬-৮ বছর', blurb: 'বর্ণ, গোনা ও সহজ পড়া', emoji: '🎈', autoRead: true },
  { id: '9-11', label: '৯-১১ বছর', blurb: 'যোগ-বিয়োগ, বিজ্ঞান, গল্প', emoji: '🚀', autoRead: false },
  { id: '12-14', label: '১২-১৪ বছর', blurb: 'একটু কঠিন চ্যালেঞ্জ', emoji: '🧠', autoRead: false },
];

export function getAgeBand(id?: string | null): AgeBandMeta | undefined {
  return AGE_BANDS.find((b) => b.id === id);
}

export function isAgeBand(v: unknown): v is AgeBand {
  return typeof v === 'string' && AGE_BANDS.some((b) => b.id === v);
}

export interface Question {
  id: string;
  question: string;
  options: [string, string, string, string];
  correctIndex: number;
  explanation: string;
}

export interface Lesson {
  id: string;
  title: string;
  questions: Question[];
}

export interface LearnCardData {
  id: string;
  big: string;
  sub: string;
  emoji: string;
  tip: string;
}

/** A graded unit within a subject for a given age band. */
export interface Level {
  id: string; // e.g. "alphabet-6-8-1"
  index: number; // 0-based order
  title: string; // e.g. "লেভেল ১"
  subtitle: string; // short focus, e.g. "স্বরবর্ণ"
  learnCards: LearnCardData[];
  questions: Question[];
  rewardCoins: number;
}

export interface LevelStatus extends Level {
  locked: boolean;
  completed: boolean;
  bestStars: number;
}

export interface Subject {
  id: string;
  name: string; // Bangla display name
  emoji: string; // used ONLY inside the mascot/subject token
  accent: 'mango' | 'leaf' | 'sun';
  description: string;
  /** whether this subject supports the drag-drop matching game */
  hasMatchGame?: boolean;
}

/** The four subjects shown in the app grid. */
export const SUBJECTS: Subject[] = [
  {
    id: 'alphabet',
    name: 'বর্ণমালা',
    emoji: '🔤',
    accent: 'mango',
    description: 'অ আ ক খ চেনা ও মিলানো',
    hasMatchGame: true,
  },
  {
    id: 'math',
    name: 'গণিত',
    emoji: '🔢',
    accent: 'leaf',
    description: 'গোনা, যোগ আর বিয়োগ',
  },
  {
    id: 'science',
    name: 'বিজ্ঞান',
    emoji: '🔬',
    accent: 'sun',
    description: 'চারপাশের মজার জিনিস',
  },
  {
    id: 'story',
    name: 'গল্প পড়া',
    emoji: '📖',
    accent: 'mango',
    description: 'ছোট গল্প ও শব্দ চেনা',
  },
];

export function getSubject(id: string): Subject | undefined {
  return SUBJECTS.find((s) => s.id === id);
}

export const SUBJECT_NAME: Record<string, string> = Object.fromEntries(
  SUBJECTS.map((s) => [s.id, s.name]),
);
