import { injectable } from "inversify" ; import type { CardSetAppearance , UnlinkedCard } from "./UnlinkedCard" ; import type { CardSet } from "./set/CardSet" ; import type { CardType } from "./type/CardType" ; import type { Card } from "./Card" ; import { getLogger } from "../logger" ; @ injectable ( ) export class CardLinkingService { private static readonly logger = getLogger ( CardLinkingService ) ; param unlinkedCard param setMap param typeMap return linkCard ( unlinkedCard , setMap , typeMap ) { return { ... unlinkedCard , type : this . #linkType ( unlinkedCard . type , typeMap ) , sets : this . #linkSets ( unlinkedCard . sets , setMap ) , } ; } #linkSets ( setAppearances , setCache ) { return setAppearances . map ( ( setAppearance ) => { if ( ! setCache . has ( setAppearance . name ) ) { CardLinkingService . logger . warn ( `Could not find set '${ setAppearance . name }'.` ) ; return null ; } const matchingSet = setCache . get ( setAppearance . name ) ! ; CardLinkingService . logger . trace ( `Matched set ${ setAppearance . name } to ${ matchingSet . name }.` ) ; return matchingSet ; } ) . filter ( ( set ) => set != null ) as CardSet [ ] ; } #linkType ( typeName , typeCache ) { if ( ! typeCache . has ( typeName ) ) { throw new TypeError ( `Could not find type '${ typeName }'.` ) ; } const matchingType = typeCache . get ( typeName ) ! ; CardLinkingService . logger . trace ( `Matched type ${ typeName } to ${ matchingType . name }.` ) ; return matchingType ; } }