package leigh.example.calcite.adapter;

import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;
import org.apache.calcite.plan.Convention;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.prepare.Prepare;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.core.TableModify;
import org.apache.calcite.rex.RexNode;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;

public class ExampleTableModify extends TableModify {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(ExampleTableModify.class);

    protected ExampleTableModify(RelOptCluster cluster, RelTraitSet traitSet, RelOptTable table,
                                 Prepare.CatalogReader catalogReader, RelNode input, Operation operation,
                                 @Nullable List<String> updateColumnList, @Nullable List<RexNode> sourceExpressionList,
                                 boolean flattened) {
        super(cluster, traitSet, table, catalogReader, input, operation,
                updateColumnList, sourceExpressionList, flattened);
    }

    @Override
    public ExampleTableModify copy(RelTraitSet traitSet,
                                   List<RelNode> inputs) {
        logger.info("copy() called");

        assert traitSet.containsIfApplicable(Convention.NONE);
        return new ExampleTableModify(getCluster(), traitSet, table, catalogReader,
                sole(inputs), getOperation(), getUpdateColumnList(),
                getSourceExpressionList(), isFlattened());
    }
}
