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

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

/**
 * @Author: 黄子奇
 * @Date: 2019/9/7 16:12
 *
 * 一层结构的逻辑节点，即类型为 and、or、not
 */
@ApiModel("一层结构的逻辑节点")
public class SimpleLogicNode implements LogicNode {

    @ApiModelProperty(value = "逻辑类型", notes = "And、Or")
    private LogicType type;

    @ApiModelProperty("二元操作节点")
    private BinOperation node;

    public SimpleLogicNode() {
    }

    public SimpleLogicNode(LogicType type, BinOperation node) {
        this.type = type;
        this.node = node;
    }

    @Override
    public LogicType getLogicType() {
        return this.type;
    }

    @Override
    public BinOperation getBinOperation() {
        return this.node;
    }

    @Override
    public boolean hasExtNodes() {
        return false;
    }

    @Override
    public List<LogicNode> getExtNodes() {
//        throw new RuntimeException("this kind of logic node doesn't have extnodes.");
        return null;
    }

    @Override
    public String toSql(SqlContext context) {
        return type.toString() + " " + node.toSql(context);
    }


    public static SimpleLogicNode And(BinOperation binOperation) {
        return new SimpleLogicNode(LogicType.AND, binOperation);
    }

    public static SimpleLogicNode Or(BinOperation binOperation) {
        return new SimpleLogicNode(LogicType.OR, binOperation);
    }

    public static SimpleLogicNode Not(BinOperation binOperation) {
        return new SimpleLogicNode(LogicType.NOT, binOperation);
    }


    public LogicType getType() {
        return type;
    }

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

    public BinOperation getNode() {
        return node;
    }

    public void setNode(BinOperation node) {
        this.node = node;
    }
}
