package com.alibaba.druid.sql.dialect.kingbase.ast.expression;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.statement.SQLIfStatement;
import com.alibaba.druid.sql.dialect.kingbase.KingbaseSQLObjectImpl;
import com.alibaba.druid.sql.dialect.kingbase.ast.statement.KingbaseStatementImpl;
import com.alibaba.druid.sql.dialect.kingbase.visitor.KingbaseASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class KingbaseCaseStatement extends KingbaseStatementImpl {
   private SQLExpr condition;
   private List<KingbaseWhenStatement> whenList = new ArrayList();
   private SQLIfStatement.Else elseItem;

   public SQLExpr getCondition() {
      return this.condition;
   }

   public void setCondition(SQLExpr condition) {
      this.condition = condition;
   }

   public List<KingbaseWhenStatement> getWhenList() {
      return this.whenList;
   }

   public void setWhenList(List<KingbaseWhenStatement> whenList) {
      this.whenList = whenList;
   }

   public void addWhenStatement(KingbaseWhenStatement stmt) {
      this.whenList.add(stmt);
   }

   public SQLIfStatement.Else getElseItem() {
      return this.elseItem;
   }

   public void setElseItem(SQLIfStatement.Else elseItem) {
      this.elseItem = elseItem;
   }

   public void accept0(KingbaseASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.condition);
         this.acceptChild(visitor, this.whenList);
         this.acceptChild(visitor, this.elseItem);
      }

      visitor.endVisit(this);
   }

   public List<SQLObject> getChildren() {
      List<SQLObject> children = new ArrayList();
      children.addAll(children);
      children.addAll(this.whenList);
      children.addAll(this.whenList);
      if (this.elseItem != null) {
         children.add(this.elseItem);
      }

      return children;
   }

   public static class KingbaseWhenStatement extends KingbaseSQLObjectImpl {
      private SQLExpr condition;
      private List<SQLStatement> statements = new ArrayList();

      public void accept0(KingbaseASTVisitor visitor) {
         if (visitor.visit(this)) {
            this.acceptChild(visitor, this.condition);
            this.acceptChild(visitor, this.statements);
         }

         visitor.endVisit(this);
      }

      public SQLExpr getCondition() {
         return this.condition;
      }

      public void setCondition(SQLExpr condition) {
         this.condition = condition;
      }

      public List<SQLStatement> getStatements() {
         return this.statements;
      }

      public void setStatements(List<SQLStatement> statements) {
         this.statements = statements;
      }
   }
}
