package thb.jeanluc.adventure.loader;

import thb.jeanluc.adventure.loader.dto.ConditionDto;
import thb.jeanluc.adventure.loader.dto.EffectDto;
import thb.jeanluc.adventure.loader.dto.QuestDto;
import thb.jeanluc.adventure.loader.dto.QuestStageDto;
import thb.jeanluc.adventure.model.Quest;
import thb.jeanluc.adventure.model.QuestStage;

import java.util.ArrayList;
import java.util.List;

/** Builds {@link Quest} objects from {@link QuestDto}s (no reference resolution needed). */
public final class QuestFactory {

    private QuestFactory() {
    }

    public static Quest fromDto(QuestDto dto) {
        List<QuestStage> stages = new ArrayList<>();
        if (dto.stages() != null) {
            for (QuestStageDto s : dto.stages()) {
                stages.add(new QuestStage(
                        s.objective(),
                        ConditionDto.toModelList(s.completion()),
                        EffectDto.toModelList(s.onComplete())));
            }
        }
        return new Quest(
                dto.id(),
                dto.title(),
                Boolean.TRUE.equals(dto.autoStart()),
                stages,
                EffectDto.toModelList(dto.onComplete()));
    }
}
