package com.easyagents.federation.sql.runtime;

import java.util.Map;
import org.apache.calcite.DataContext;
import org.apache.calcite.adapter.java.JavaTypeFactory;
import org.apache.calcite.linq4j.QueryProvider;
import org.apache.calcite.schema.SchemaPlus;

/**
 * 为节点本地 Bindable 提供分片 Schema、动态参数和执行会话。
 */
final class FederationDataContext implements DataContext {

    private final SchemaPlus rootSchema;
    private final JavaTypeFactory typeFactory;
    private final Map<String, Object> values;

    /**
     * 创建联邦 DataContext。
     *
     * @param rootSchema 分片占位表所在根 Schema
     * @param typeFactory Calcite Java 类型工厂
     * @param values 查询参数和执行会话
     */
    FederationDataContext(
        SchemaPlus rootSchema,
        JavaTypeFactory typeFactory,
        Map<String, Object> values
    ) {
        this.rootSchema = rootSchema;
        this.typeFactory = typeFactory;
        this.values = values;
    }

    /** {@inheritDoc} */
    @Override
    public SchemaPlus getRootSchema() {
        return rootSchema;
    }

    /** {@inheritDoc} */
    @Override
    public JavaTypeFactory getTypeFactory() {
        return typeFactory;
    }

    /** {@inheritDoc} */
    @Override
    public QueryProvider getQueryProvider() {
        throw new UnsupportedOperationException("query provider is not required for fragment scans");
    }

    /** {@inheritDoc} */
    @Override
    public Object get(String name) {
        return values.get(name);
    }
}
