package com.pixelized.server.lwa.services.map

import com.pixelized.server.lwa.server.exception.BusinessException
import com.pixelized.shared.lwa.model.map.MapJson

class MapService(
    private val mapStore: MapStore,
) {
    fun maps(): List<MapJson> {
        return mapStore.maps().value.values.toList()
    }

    @Throws
    fun map(id: String): MapJson {
        return mapStore.maps().value[id]
            ?: throw BusinessException("Map with id:$id is not found")
    }

    @Throws
    suspend fun save(
        json: MapJson,
        create: Boolean,
    ) {
        mapStore.save(
            map = json,
            create = create,
        )
    }

    @Throws
    fun delete(mapId: String) {
        mapStore.delete(id = mapId)
    }
}
