package click.kamil.examples.statemachine.layered.dispatch;

import click.kamil.examples.statemachine.layered.command.DomainCommand;
import org.springframework.stereotype.Component;

@Component
public class StringCommandMapper {

    public DomainCommand fromString(String commandKey) {
        if (commandKey == null) {
            throw new IllegalArgumentException("commandKey must not be null");
        }
        return switch (commandKey) {
            case "order.pay" -> DomainCommand.ORDER_PAY;
            case "order.ship" -> DomainCommand.ORDER_SHIP;
            case "order.cancel" -> DomainCommand.ORDER_CANCEL;
            case "document.submit" -> DomainCommand.DOCUMENT_SUBMIT;
            case "document.approve" -> DomainCommand.DOCUMENT_APPROVE;
            case "document.reject" -> DomainCommand.DOCUMENT_REJECT;
            default -> throw new IllegalArgumentException("Unknown command: " + commandKey);
        };
    }
}
