/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */
package org.elasticsearch.xpack.sql.expression.function.scalar.string;

import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.string.StringProcessor.StringOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;

/**
 * Converts an int ASCII code to a character value.
 */
public class Char extends UnaryStringIntFunction {

    public Char(Location location, Expression field) {
        super(location, field);
    }

    @Override
    protected NodeInfo<Char> info() {
        return NodeInfo.create(this, Char::new, field());
    }

    @Override
    protected Char replaceChild(Expression newChild) {
        return new Char(location(), newChild);
    }

    @Override
    protected StringOperation operation() {
        return StringOperation.CHAR;
    }

    @Override
    public DataType dataType() {
        return DataType.KEYWORD;
    }
}