package liquibase.ext.percona;

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.sql.SQLException;
import java.util.List;
import java.util.concurrent.Executor;

import org.mariadb.jdbc.Configuration;
import org.mariadb.jdbc.Connection;
import org.mariadb.jdbc.HostAddress;
import org.mariadb.jdbc.Statement;
import org.mariadb.jdbc.client.Client;
import org.mariadb.jdbc.client.Completion;
import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.PrepareCache;
import org.mariadb.jdbc.client.ServerVersion;
import org.mariadb.jdbc.export.ExceptionFactory;
import org.mariadb.jdbc.export.Prepare;
import org.mariadb.jdbc.message.ClientMessage;
import org.mariadb.jdbc.message.server.util.ServerVersionUtility;

public class MockedMariaDbConnection {

    public static java.sql.Connection create(Configuration config) throws SQLException {
        Connection mariadbConnection = new Connection(config, null, new NoopMariaDbClient(config));
        return mariadbConnection;
    }

    private static class NoopMariaDbClient implements Client {
        private Configuration config;

        public NoopMariaDbClient(Configuration config) {
            this.config = config;
        }

        @Override
        public Context getContext() {
            return new MockedContext(config);
        }

        @Override
        public ExceptionFactory getExceptionFactory() {
            return new ExceptionFactory(this.config, null);
        }

        @Override
        public List<Completion> execute(ClientMessage message, boolean canRedo) throws SQLException {
            return null;
        }

        @Override
        public List<Completion> execute(ClientMessage message, Statement stmt, boolean canRedo) throws SQLException {
            return null;
        }

        @Override
        public List<Completion> execute(ClientMessage message, Statement stmt, int fetchSize, long maxRows,
                int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo)
                throws SQLException {
            return null;
        }

        @Override
        public List<Completion> executePipeline(ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows,
                int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo)
                throws SQLException {
            return null;
        }

        @Override
        public void readStreamingResults(List<Completion> completions, int fetchSize, long maxRows,
                int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws SQLException {
        }

        @Override
        public void closePrepare(Prepare prepare) throws SQLException {
        }

        @Override
        public void abort(Executor executor) throws SQLException {
        }

        @Override
        public void close() throws SQLException {
        }

        @Override
        public void setReadOnly(boolean readOnly) throws SQLException {
        }

        @Override
        public int getSocketTimeout() {
            return 0;
        }

        @Override
        public void setSocketTimeout(int milliseconds) throws SQLException {
        }

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

        @Override
        public void reset() {
        }

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

        @Override
        public HostAddress getHostAddress() {
            return null;
        }
    }

    private static class MockedContext implements Context {
        private Configuration config;

        public MockedContext(Configuration config) {
            this.config = config;
        }

        @Override
        public Configuration getConf() {
            return config;
        }

        @Override
        public ServerVersion getVersion() {
            return new ServerVersionUtility("0", false);
        }

        @Override
        public void setWarning(int warning) {
        }

        @Override
        public void setTransactionIsolationLevel(int transactionIsolationLevel) {
        }

        @Override
        public void setServerStatus(int serverStatus) {
        }

        @Override
        public void setDatabase(String database) {
        }

        @Override
        public void resetStateFlag() {
        }

        @Override
        public void resetPrepareCache() {
        }

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

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

        @Override
        public int getWarning() {
            return 0;
        }

        @Override
        public int getTransactionIsolationLevel() {
            return 0;
        }

        @Override
        public long getThreadId() {
            return 0;
        }

        @Override
        public int getStateFlag() {
            return 0;
        }

        @Override
        public int getServerStatus() {
            return 0;
        }

        @Override
        public long getServerCapabilities() {
            return 0;
        }

        @Override
        public byte[] getSeed() {
            return null;
        }

        @Override
        public PrepareCache getPrepareCache() {
            return null;
        }

        @Override
        public ExceptionFactory getExceptionFactory() {
            return null;
        }

        @Override
        public String getDatabase() {
            return null;
        }

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

        @Override
        public void addStateFlag(int state) {
        }
    }
}

@@ -5679,24 +5679,115 @@
  public 
-long get
+byte%5B%5D getSeed() %7B%0A            return null;%0A        %7D%0A%0A        @Override%0A        public boolean has
 ServerCa
@@ -5797,12 +5797,16 @@
 ilit
-ies(
+y(long l
 ) %7B%0A
@@ -5816,33 +5816,37 @@
          return 
-0
+false
 ;%0A        %7D%0A%0A   
@@ -5872,38 +5872,57 @@
     public b
-yte%5B%5D getSeed(
+oolean hasClientCapability(long l
 ) %7B%0A        
@@ -5924,36 +5924,37 @@
          return 
-null
+false
 ;%0A        %7D%0A%0A   

Fix compile errors with new MariaDB Connector