package function.builtin;

import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Atom;
import sexpression.Cons;
import sexpression.LispString;
import sexpression.SExpression;
import sexpression.Symbol;

@FunctionNames({ "FUSE" })
public class FUSE extends LispFunction {

    private static final String SEPARATOR = "-";

    private ArgumentValidator argumentValidator;

    public FUSE(String name) {
        this.argumentValidator = new ArgumentValidator(name);
        this.argumentValidator.setExactNumberOfArguments(2);
        this.argumentValidator.setFirstArgumentExpectedType(Symbol.class);
        this.argumentValidator.setTrailingArgumentExpectedType(Atom.class);
        this.argumentValidator.setTrailingArgumentExcludedType(LispString.class);
    }

    @Override
    public SExpression call(Cons argumentList) {
        argumentValidator.validate(argumentList);
        Symbol left = (Symbol) argumentList.getFirst();
        Atom right = (Atom) ((Cons) argumentList.getRest()).getFirst();

        return new Symbol(left.toString() + SEPARATOR + right.toString());
    }

}
