package com.loremind.infrastructure.web.mapper;

import com.loremind.domain.campaigncontext.Arc;
import com.loremind.infrastructure.web.dto.campaigncontext.ArcDTO;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * Mapper pour convertir entre Arc (entité de domaine) et ArcDTO.
 */
@Component
public class ArcMapper {

    public ArcDTO toDTO(Arc arc) {
        if (arc == null) {
            return null;
        }
        
        ArcDTO dto = new ArcDTO();
        dto.setId(arc.getId());
        dto.setName(arc.getName());
        dto.setDescription(arc.getDescription());
        dto.setCampaignId(arc.getCampaignId());
        dto.setOrder(arc.getOrder());
        dto.setThemes(arc.getThemes());
        dto.setStakes(arc.getStakes());
        dto.setGmNotes(arc.getGmNotes());
        dto.setRewards(arc.getRewards());
        dto.setResolution(arc.getResolution());
        dto.setRelatedPageIds(arc.getRelatedPageIds() != null
                ? new ArrayList<>(arc.getRelatedPageIds())
                : new ArrayList<>());
        return dto;
    }

    public Arc toDomain(ArcDTO dto) {
        if (dto == null) {
            return null;
        }
        
        return Arc.builder()
                .id(dto.getId())
                .name(dto.getName())
                .description(dto.getDescription())
                .campaignId(dto.getCampaignId())
                .order(dto.getOrder())
                .themes(dto.getThemes())
                .stakes(dto.getStakes())
                .gmNotes(dto.getGmNotes())
                .rewards(dto.getRewards())
                .resolution(dto.getResolution())
                .relatedPageIds(dto.getRelatedPageIds() != null
                        ? new ArrayList<>(dto.getRelatedPageIds())
                        : new ArrayList<>())
                .build();
    }
}
