import { Injectable } from '@angular/core' ; import { Card } from '../../models/card' ; import { CardBack } from '../../models/card-back' ; import { CardHistory } from '../../models/card-history' ; import { Coin } from '../../models/coin' ; import { PackInfo } from '../../models/collection/pack-info' ; import { LocalStorageService } from '../local-storage' ; declare let amplitude ; @ Injectable ( ) export class CollectionStorageService { constructor ( private readonly localStorageService ) { } public async saveCollection ( collection ) { this . localStorageService . setItem ( LocalStorageService . LOCAL_STORAGE_COLLECTION , collection ) ; return collection ; } public async saveBattlegroundsOwnedHeroSkinDbfIds ( collection ) { this . localStorageService . setItem ( LocalStorageService . LOCAL_STORAGE_BGS_HERO_SKIN_IDS , collection ) ; return collection ; } public async saveCardBacks ( cardBacks ) { this . localStorageService . setItem ( LocalStorageService . LOCAL_STORAGE_CARD_BACKS , cardBacks ) ; return cardBacks ; } public async savePackInfos ( packInfos ) { this . localStorageService . setItem ( LocalStorageService . LOCAL_STORAGE_PACK_INFOS , packInfos ) ; return packInfos ; } public async saveCoins ( coins ) { this . localStorageService . setItem ( LocalStorageService . LOCAL_STORAGE_COINS , coins ) ; return coins ; } public async getBattlegroundsOwnedHeroSkinDbfIds ( ) { return this . localStorageService . getItem ( LocalStorageService . LOCAL_STORAGE_BGS_HERO_SKIN_IDS ) ?? [ ] ; } public async getCollection ( ) { const fromStorage = this . localStorageService . getItem ( LocalStorageService . LOCAL_STORAGE_COLLECTION ) ; return fromStorage ?? [ ] ; } public async getCardBacks ( ) { const fromStorage = this . localStorageService . getItem ( LocalStorageService . LOCAL_STORAGE_CARD_BACKS ) ; return fromStorage ?? [ ] ; } public async getPackInfos ( ) { const fromStorage = this . localStorageService . getItem ( LocalStorageService . LOCAL_STORAGE_PACK_INFOS ) ; return fromStorage ?? [ ] ; } public async getCoins ( ) { const fromStorage = this . localStorageService . getItem ( LocalStorageService . LOCAL_STORAGE_COINS ) ; return fromStorage ?? [ ] ; } public async saveCardHistory ( history ) { const fromStorage = this . localStorageService . getItem ( LocalStorageService . LOCAL_STORAGE_CARDS_HISTORY ) ; const historyList = fromStorage ?? [ ] ; const newHistory = [ history , ... historyList ] ; this . localStorageService . setItem ( LocalStorageService . LOCAL_STORAGE_CARDS_HISTORY , newHistory ) ; return history ; } public async saveFullCardHistory ( history ) { this . localStorageService . setItem ( LocalStorageService . LOCAL_STORAGE_CARDS_HISTORY , history ) ; return history ?? [ ] ; } public async countCardHistory ( ) { const fullHistory = await this . getAllCardHistory ( 0 ) ; return fullHistory . length ; } public async getAllCardHistory ( limit ) { const fromStorage = this . localStorageService . getItem ( LocalStorageService . LOCAL_STORAGE_CARDS_HISTORY ) ; if ( ! ! fromStorage ) { const result = fromStorage ?? [ ] ; return result . slice ( 0 , limit ) ; } return [ ] ; } }