import { inject , injectable } from "inversify" ; import type { Deck } from "./Deck" ; import { TYPES } from "../types" ; import type { Card } from "../card/Card" ; import { DeckService } from "./DeckService" ; import { DefaultDeckPartConfig } from "./DeckPartConfig" ; import { CardService } from "../card/CardService" ; import { CardTypeCategory } from "../card/type/CardTypeCategory" ; import { FilterService } from "../card/FilterService" ; import { DECK_PART_ARR , DeckPart } from "./DeckPart" ; @ injectable ( ) export class DeckExportService { readonly #deckService : DeckService ; readonly #cardService : CardService ; readonly #filterService : FilterService ; constructor ( @ inject ( TYPES . DeckService ) deckService , @ inject ( TYPES . CardService ) cardService , @ inject ( TYPES . FilterService ) filterService ) { this . #deckService = deckService ; this . #cardService = cardService ; this . #filterService = filterService ; } param deck return toShareableText ( deck ) { const result = [ ] ; for ( const deckPart of DECK_PART_ARR ) { const cards = deck . parts [ deckPart ] ; if ( deckPart === DeckPart . MAIN ) { for ( const typeCategory of Object . values ( CardTypeCategory ) ) { result . push ( ... this . #createCardList ( typeCategory , this . #filterService . filter ( cards , { typeCategory : typeCategory , } ) ) ) ; } } else { result . push ( ... this . #createCardList ( DefaultDeckPartConfig [ deckPart ] . name , cards ) ) ; } } return result . join ( "\n" ) ; } #createCardList ( sectionName , cards ) { if ( cards . length === 0 ) { return [ ] ; } const result = [ ] ; result . push ( `${ sectionName }:` ) ; result . push ( ... this . #cardService . createFormattedCardCountList ( cards ) ) ; result . push ( "" ) ; return result ; } see https param deck param affiliate return toBuyLink ( deck , affiliate ) { const countedCards = this . #cardService . countByCard ( this . #deckService . getAllCards ( deck ) ) ; const cardListUriParam = Array . from ( countedCards . entries ( ) ) . map ( ( [ card , count ] ) => `${ count } ${ card . name }` ) . join ( "||" ) + "||" ; const buyLink = new URL ( "massentry" , "https://www.tcgplayer.com" ) ; buyLink . searchParams . append ( "productline" , "Yugioh" ) ; if ( affiliate != null ) { buyLink . searchParams . append ( "utm_campaign" , "affiliate" ) ; buyLink . searchParams . append ( "utm_medium" , affiliate . medium ) ; buyLink . searchParams . append ( "utm_source" , affiliate . source ) ; } buyLink . searchParams . append ( "c" , cardListUriParam ) ; return buyLink ; } }