package com.liangjian.dataplatform.member.entity.vo.tagrules;

import com.liangjian.dataplatform.member.entity.vo.datanodes.PDMColumn;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @Author: 黄子奇
 * @Date: 2019/9/7 14:41
 *
 * 二元操作，参考语法树的，
 * 如 [left] eq [right] ,  [left] le [right]
 */
@ApiModel("二元操作")
public class BinOperation implements ToSqlable {

    @ApiModelProperty("二元操作类型")
    protected BinOperaType type;
    @ApiModelProperty("左值所对应的表id")
    protected String leftTableId;
    @ApiModelProperty("左值")
    protected PDMColumn left;
    @ApiModelProperty("右值")
    protected String right;

    public BinOperation() {
    }

    public BinOperation(BinOperaType type, PDMColumn left, String right) {
        this.type = type;
        this.left = left;
        this.right = right;
    }

    public BinOperaType getType() {
        return type;
    }

    public void setType(BinOperaType type) {
        this.type = type;
    }

    public void setLeft(PDMColumn left) {
        this.left = left;
    }

    public void setRight(String right) {
        this.right = right;
    }

    public PDMColumn getLeft() {
        return left;
    }

    public String getRight() {
        return right;
    }

    public String getLeftTableId() {
        return leftTableId;
    }

    public void setLeftTableId(String leftTableId) {
        this.leftTableId = leftTableId;
    }

    @Override
    public String toSql(SqlContext context) {
        String colName = this.left.getName();
        String tableName = context.getTableAlias(this.leftTableId);
        String leftStr = tableName + "." + colName;
        return this.type.toSql(leftStr, right);
    }
}