/** §4 NPC roster */

export type NpcId =
  | 'afu'
  | 'yuanyuan'
  | 'dabao'
  | 'mimi'
  | 'fu'
  | 'twinbirds'
  | 'gui'
  | 'extra1'
  | 'extra2'
  | 'extra3'
  | 'extra4'
  | 'extra5';

export interface NpcDef {
  id: NpcId;
  displayName: string;
  /** Permanent map scene key */
  homeScene: string;
  /** Threshold offset; 'immune' for 芙医生 / 龟爷爷 */
  offset: number | 'immune';
  hasDialog: boolean;
  isExtra: boolean;
}

export const NPCS: readonly NpcDef[] = [
  {
    id: 'afu',
    displayName: '阿福',
    homeScene: 'PlazaScene',
    offset: 0,
    hasDialog: true,
    isExtra: false,
  },
  {
    id: 'yuanyuan',
    displayName: '圆圆',
    homeScene: 'BakeryScene',
    offset: 15,
    hasDialog: true,
    isExtra: false,
  },
  {
    id: 'dabao',
    displayName: '大宝',
    homeScene: 'PlazaScene',
    offset: 0,
    hasDialog: true,
    isExtra: false,
  },
  {
    id: 'mimi',
    displayName: '咪咪',
    homeScene: 'ShopScene',
    offset: -10,
    hasDialog: true,
    isExtra: false,
  },
  {
    id: 'fu',
    displayName: '芙医生',
    homeScene: 'ClinicScene',
    offset: 'immune',
    hasDialog: true,
    isExtra: false,
  },
  {
    id: 'twinbirds',
    displayName: '双子鸟',
    homeScene: 'PlazaScene',
    offset: 0,
    hasDialog: false,
    isExtra: false,
  },
  {
    id: 'gui',
    displayName: '龟爷爷',
    homeScene: 'LakeScene',
    offset: 'immune',
    hasDialog: true,
    isExtra: false,
  },
  {
    id: 'extra1',
    displayName: '松鼠',
    homeScene: 'PlazaScene',
    offset: 0,
    hasDialog: false,
    isExtra: true,
  },
  {
    id: 'extra2',
    displayName: '刺猬',
    homeScene: 'FieldScene',
    offset: 0,
    hasDialog: false,
    isExtra: true,
  },
  {
    id: 'extra3',
    displayName: '小松鼠',
    homeScene: 'LakeScene',
    offset: 0,
    hasDialog: false,
    isExtra: true,
  },
  {
    id: 'extra4',
    displayName: '小鸟',
    homeScene: 'PlazaScene',
    offset: 0,
    hasDialog: false,
    isExtra: true,
  },
  {
    id: 'extra5',
    displayName: '小刺猬',
    homeScene: 'WellScene',
    offset: 0,
    hasDialog: false,
    isExtra: true,
  },
] as const;

export function getNpc(id: NpcId): NpcDef {
  const n = NPCS.find((x) => x.id === id);
  if (!n) throw new Error(`Unknown NPC ${id}`);
  return n;
}
