package com.jy.framework.mybatis.join;

import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.stream.Collectors;

public class QueryFunction extends AbstractQueryColumn {

    /**
     * 方法名
     */
    private final String fnName;

    /**
     * 方法参数
     */
    private final Object[] columns;

    protected QueryFunction(String fnName, Object... columns) {
        this.fnName = fnName;
        this.columns = columns;
    }

    @Override
    protected QueryFunction copy() {
        return new QueryFunction(this.fnName, this.columns);
    }

    @Override
    protected String format() {
        String sql = this.fnName + Arrays.stream(columns)
                .map(SqlContext::formatValue)
                .collect(Collectors.joining(StringPool.COMMA, StringPool.LEFT_BRACKET, StringPool.RIGHT_BRACKET));

        return spliceCompute(sql);
    }

}
