package com.loremind.infrastructure.web.mapper;

import com.loremind.domain.campaigncontext.Scene;
import com.loremind.infrastructure.web.dto.campaigncontext.SceneDTO;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * Mapper pour convertir entre Scene (entité de domaine) et SceneDTO.
 */
@Component
public class SceneMapper {

    public SceneDTO toDTO(Scene scene) {
        if (scene == null) {
            return null;
        }
        
        SceneDTO dto = new SceneDTO();
        dto.setId(scene.getId());
        dto.setName(scene.getName());
        dto.setDescription(scene.getDescription());
        dto.setChapterId(scene.getChapterId());
        dto.setOrder(scene.getOrder());
        dto.setLocation(scene.getLocation());
        dto.setTiming(scene.getTiming());
        dto.setAtmosphere(scene.getAtmosphere());
        dto.setPlayerNarration(scene.getPlayerNarration());
        dto.setGmSecretNotes(scene.getGmSecretNotes());
        dto.setChoicesConsequences(scene.getChoicesConsequences());
        dto.setCombatDifficulty(scene.getCombatDifficulty());
        dto.setEnemies(scene.getEnemies());
        dto.setRelatedPageIds(scene.getRelatedPageIds() != null
                ? new ArrayList<>(scene.getRelatedPageIds())
                : new ArrayList<>());
        return dto;
    }

    public Scene toDomain(SceneDTO dto) {
        if (dto == null) {
            return null;
        }
        
        return Scene.builder()
                .id(dto.getId())
                .name(dto.getName())
                .description(dto.getDescription())
                .chapterId(dto.getChapterId())
                .order(dto.getOrder())
                .location(dto.getLocation())
                .timing(dto.getTiming())
                .atmosphere(dto.getAtmosphere())
                .playerNarration(dto.getPlayerNarration())
                .gmSecretNotes(dto.getGmSecretNotes())
                .choicesConsequences(dto.getChoicesConsequences())
                .combatDifficulty(dto.getCombatDifficulty())
                .enemies(dto.getEnemies())
                .relatedPageIds(dto.getRelatedPageIds() != null
                        ? new ArrayList<>(dto.getRelatedPageIds())
                        : new ArrayList<>())
                .build();
    }
}
