/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */

package org.apache.seatunnel.connectors.seatunnel.preview.config;

import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
import lombok.NonNull;

import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class RedisClusterClient implements RedisClient{
    private final RedisAdvancedClusterCommands<String, String> redisCommands;

    public RedisClusterClient(@NonNull RedisAdvancedClusterCommands<String, String> clusterCommands) {
        this.redisCommands = clusterCommands;
    }

    @Override
    public String set(final String key, final String value) {
        return redisCommands.set(key, value);
    }

    @Override
    public String get(final String key) {
        return redisCommands.get(key);
    }

    @Override
    public boolean hset(final String key, final String field, final String value) {
        return redisCommands.hset(key, field, value);
    }

    @Override
    public Map<String, String> hgetAll(final String key) {
        return redisCommands.hgetall(key);
    }

    @Override
    public long lpush(final String key, final String... strings) {
        return redisCommands.lpush(key, strings);
    }

    @Override
    public List<String> lrange(final String key, final long start, final long stop) {
        return redisCommands.lrange(key, start, stop);
    }

    @Override
    public long sadd(final String key, final String... members) {
        return redisCommands.sadd(key, members);
    }

    @Override
    public Set<String> smembers(final String key) {
        return redisCommands.smembers(key);
    }

    @Override
    public long zadd(final String key, final double score, final String member) {
        return redisCommands.zadd(key, score, member);
    }

    @Override
    public List<String> zrange(final String key, final long start, final long stop) {
        return redisCommands.zrange(key, start, stop);
    }

    @Override
    public void close() {
    }

    @Override
    public void expire(String key, Duration duration) {
        redisCommands.expire(key, duration.getSeconds());
    }
}
