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

import com.pixelized.shared.lwa.model.campaign.Campaign
import com.pixelized.shared.lwa.model.campaign.CampaignJsonV2
import com.pixelized.shared.lwa.model.map.Map

class CampaignJsonV2Factory {

    fun convertFromJson(
        campaignJson: CampaignJsonV2,
    ): Campaign {
        return Campaign(
            characters = campaignJson.characters,
            npcs = campaignJson.npcs,
            map = campaignJson.map
                ?.let { convertFromJson(mapJson = it) }
                ?: Campaign.MiniMap.empty(),
            scene = campaignJson.scene
                ?.let { convertFromJson(sceneJson = it) }
                ?: Campaign.Scene.empty(),
            options = campaignJson.options
                ?.let { convertFromJson(optionsJson = it) }
                ?: Campaign.Options.empty()
        )
    }

    fun convertFromJson(
        mapJson: CampaignJsonV2.MiniMapJson,
    ): Campaign.MiniMap {
        return Campaign.MiniMap(
            id = mapJson.id,
            camera = mapJson.camera?.let {
                Map.Camera(
                    zoom = it.zoom,
                    offsetX = it.offsetX,
                    offsetY = it.offsetY,
                )
            }
        )
    }

    fun convertFromJson(
        sceneJson: CampaignJsonV2.SceneJsonV2,
    ): Campaign.Scene {
        return Campaign.Scene(
            name = sceneJson.name
        )
    }

    fun convertFromJson(
        optionsJson: CampaignJsonV2.OptionsJsonV2,
    ): Campaign.Options {
        return Campaign.Options(
            showParty = optionsJson.showPlayer,
            showNpcs = optionsJson.showNpcs
        )
    }
}