// automatically generated by the FlatBuffers compiler, do not modify

import { Attacker, AttackerT } from './attacker.js';
import { BookReader, BookReaderT } from './book-reader.js';
import { Rapunzel, RapunzelT } from './rapunzel.js';


export enum Character {
  NONE = 0,
  MuLan = 1,
  Rapunzel = 2,
  Belle = 3,
  BookFan = 4,
  Other = 5,
  Unused = 6
}

export function unionToCharacter(
  type: Character,
  accessor: (obj:Attacker|BookReader|Rapunzel|string) => Attacker|BookReader|Rapunzel|string|null
): Attacker|BookReader|Rapunzel|string|null {
  switch(Character[type]) {
    case 'NONE': return null; 
    case 'MuLan': return accessor(new Attacker())! as Attacker;
    case 'Rapunzel': return accessor(new Rapunzel())! as Rapunzel;
    case 'Belle': return accessor(new BookReader())! as BookReader;
    case 'BookFan': return accessor(new BookReader())! as BookReader;
    case 'Other': return accessor('') as string;
    case 'Unused': return accessor('') as string;
    default: return null;
  }
}

export function unionListToCharacter(
  type: Character, 
  accessor: (index: number, obj:Attacker|BookReader|Rapunzel|string) => Attacker|BookReader|Rapunzel|string|null, 
  index: number
): Attacker|BookReader|Rapunzel|string|null {
  switch(Character[type]) {
    case 'NONE': return null; 
    case 'MuLan': return accessor(index, new Attacker())! as Attacker;
    case 'Rapunzel': return accessor(index, new Rapunzel())! as Rapunzel;
    case 'Belle': return accessor(index, new BookReader())! as BookReader;
    case 'BookFan': return accessor(index, new BookReader())! as BookReader;
    case 'Other': return accessor(index, '') as string;
    case 'Unused': return accessor(index, '') as string;
    default: return null;
  }
}
