package thb.jeanluc.adventure.model;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import thb.jeanluc.adventure.model.item.Item;

import java.util.List;
import java.util.Map;

/**
 * Aggregate root holding every entity in the game world plus global
 * metadata read from {@code game.yaml}. Produced by the
 * {@code WorldLoader} and handed to the game loop.
 */
@Getter
@RequiredArgsConstructor
public class World {

    /** Global lookup of rooms by id. */
    private final Map<String, Room> rooms;

    /** Global lookup of item prototypes by id. */
    private final Map<String, Item> items;

    /** Global lookup of NPCs by id. */
    private final Map<String, Npc> npcs;

    /** Display title shown to the player at startup. */
    private final String title;

    /** Welcome message printed once when the game starts. */
    private final String welcomeMessage;

    /** Global lookup of quests by id. */
    private final Map<String, Quest> quests;

    /** Ordered list of endings (first matching one wins). */
    private final List<Ending> endings;

    /** Global lookup of combination recipes by canonical pair key. */
    private final Map<String, Combination> combinations;

    /** Backward-compatible constructor for worlds without quests, endings, or combinations. */
    public World(Map<String, Room> rooms, Map<String, Item> items, Map<String, Npc> npcs,
                 String title, String welcomeMessage) {
        this(rooms, items, npcs, title, welcomeMessage, Map.of(), List.of(), Map.of());
    }

    /** Backward-compatible constructor for worlds with quests but no endings/combinations. */
    public World(Map<String, Room> rooms, Map<String, Item> items, Map<String, Npc> npcs,
                 String title, String welcomeMessage, Map<String, Quest> quests) {
        this(rooms, items, npcs, title, welcomeMessage, quests, List.of(), Map.of());
    }

    /** Backward-compatible constructor for worlds with quests + endings but no combinations. */
    public World(Map<String, Room> rooms, Map<String, Item> items, Map<String, Npc> npcs,
                 String title, String welcomeMessage, Map<String, Quest> quests, List<Ending> endings) {
        this(rooms, items, npcs, title, welcomeMessage, quests, endings, Map.of());
    }
}
