package thb.jeanluc.adventure.command.impl;

import lombok.RequiredArgsConstructor;
import thb.jeanluc.adventure.command.Command;
import thb.jeanluc.adventure.game.GameContext;
import thb.jeanluc.adventure.save.SaveException;
import thb.jeanluc.adventure.save.SaveService;

import java.util.List;

/** Manually saves the active slot. Usage: {@code save}. */
@RequiredArgsConstructor
public class SaveCommand implements Command {

    private final SaveService saves;

    @Override
    public void execute(GameContext ctx, List<String> args) {
        try {
            saves.save(ctx.getSession());
            ctx.getIo().write("Game saved.");
        } catch (SaveException e) {
            ctx.getIo().write(e.getUserMessage());
        }
    }

    @Override
    public String help() {
        return "save  -  save your game to the current slot";
    }
}
