package com.pixelized.shared.lwa.model.map.factory

import com.pixelized.shared.lwa.model.map.Map
import com.pixelized.shared.lwa.model.map.MapJson
import com.pixelized.shared.lwa.model.map.MapJsonV1

class MapJsonFactory(
    private val v1: MapJsonFactoryV1,
) {

    fun convertFromJson(
        json: MapJson,
    ): Map {
        return when (json) {
            is MapJsonV1 -> v1.convertFromJson(json = json)
        }
    }

    fun convertToJson(
        item: Map,
    ): MapJson {
        return MapJsonV1(
            id = item.id,
            name = item.name,
            camera = MapJsonV1.Camera(
                zoom = item.camera.zoom,
                offsetX = item.camera.offsetX,
                offsetY = item.camera.offsetY,
            ),
            size = MapJsonV1.Size(
                width = item.size.width,
                height = item.size.height,
            ),
            resources = item.resources.map {
                MapJsonV1.Resource(
                    id = it.id,
                    name = it.name,
                    uri = it.uri,
                )
            },
        )
    }
}