package com.alibaba.druid.sql.dialect.mariadb.ast.statement;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
import com.alibaba.druid.sql.ast.statement.SQLAlterStatement;
import com.alibaba.druid.sql.dialect.mariadb.visitor.MariadbASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class MariadbAlterUserStatement extends MariadbStatementImpl implements SQLAlterStatement {
   private boolean ifExists = false;
   private final List<AlterUser> alterUsers = new ArrayList();
   private PasswordOption passwordOption;

   public void accept0(MariadbASTVisitor visitor) {
      if (visitor.visit(this)) {
         for(AlterUser alterUser : this.alterUsers) {
            this.acceptChild(visitor, alterUser.user);
         }

         if (this.passwordOption != null && this.passwordOption.getIntervalDays() != null) {
            this.acceptChild(visitor, this.passwordOption.getIntervalDays());
         }
      }

      visitor.endVisit(this);
   }

   public boolean isIfExists() {
      return this.ifExists;
   }

   public void setIfExists(boolean ifExists) {
      this.ifExists = ifExists;
   }

   public List<SQLExpr> getUsers() {
      List<SQLExpr> users = new ArrayList();

      for(AlterUser alterUser : this.alterUsers) {
         users.add(alterUser.user);
      }

      return users;
   }

   public List<AlterUser> getAlterUsers() {
      return this.alterUsers;
   }

   public PasswordOption getPasswordOption() {
      return this.passwordOption;
   }

   public void setPasswordOption(PasswordOption passwordOption) {
      this.passwordOption = passwordOption;
   }

   public static class AuthOption {
      private SQLCharExpr authString;

      public SQLCharExpr getAuthString() {
         return this.authString;
      }

      public void setAuthString(SQLCharExpr authString) {
         this.authString = authString;
      }
   }

   public static class AlterUser {
      private SQLExpr user;
      private AuthOption authOption;

      public SQLExpr getUser() {
         return this.user;
      }

      public void setUser(SQLExpr user) {
         this.user = user;
      }

      public AuthOption getAuthOption() {
         return this.authOption;
      }

      public void setAuthOption(AuthOption authOption) {
         this.authOption = authOption;
      }
   }

   public static class PasswordOption {
      private PasswordExpire expire;
      private SQLIntegerExpr intervalDays;

      public PasswordExpire getExpire() {
         return this.expire;
      }

      public void setExpire(PasswordExpire expire) {
         this.expire = expire;
      }

      public SQLIntegerExpr getIntervalDays() {
         return this.intervalDays;
      }

      public void setIntervalDays(SQLIntegerExpr intervalDays) {
         this.intervalDays = intervalDays;
      }
   }

   public static enum PasswordExpire {
      PASSWORD_EXPIRE,
      PASSWORD_EXPIRE_DEFAULT,
      PASSWORD_EXPIRE_NEVER,
      PASSWORD_EXPIRE_INTERVAL;
   }
}
