//
//  TournamentLibrary.swift
//  PadelClub
//
//  Created by Laurent Morvillier on 11/11/2024.
//

import Foundation
import LeStorage

class TournamentLibrary {
    
    static let shared: TournamentLibrary = TournamentLibrary()
    
    fileprivate var _stores: [String : TournamentStore] = [:]
    
    func store(tournamentId: String) -> TournamentStore? {
        guard let tournament = DataStore.shared.tournaments.first(where: { $0.id == tournamentId }) else { return nil }
        
        if let store = self._stores[tournamentId] {
            return store
        }
        let store = StoreCenter.main.store(identifier: tournamentId)
        let tournamentStore = TournamentStore(store: store)
        self._stores[tournamentId] = tournamentStore
        return tournamentStore
    }
    
    func reset() {
        self._stores.removeAll()
    }
    
}
