/*
 * 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.datasource.plugin.redis;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class RedisAConfiguration {

    public static RedisConfiguration getConfiguration(Map<String, String> redisOption) {

        if (!redisOption.containsKey(RedisOptionRule.HOST.key())) {
            throw new IllegalArgumentException(
                    "redis datasource host is null, please check your config");
        }
        if (!redisOption.containsKey(RedisOptionRule.PORT.key())) {
            throw new IllegalArgumentException(
                    "redis datasource port is null, please check your config");
        }
        if (!redisOption.containsKey(RedisOptionRule.MODE.key())) {
            throw new IllegalArgumentException(
                    "redis datasource mode is null, please check your config");
        }
        if (!redisOption.containsKey(RedisOptionRule.AUTH.key())) {
            throw new IllegalArgumentException(
                    "redis datasource auth is null, please check your config");
        }
        if (!redisOption.containsKey(RedisOptionRule.KEY.key())) {
            throw new IllegalArgumentException(
                    "redis datasource key is null, please check your config");
        }
        if (!redisOption.containsKey(RedisOptionRule.DATA_TYPE.key())) {
            throw new IllegalArgumentException(
                    "redis datasource data_type is null, please check your config");
        }
        RedisConfiguration redisConfiguration = new RedisConfiguration();
        redisConfiguration.setHost(redisOption.get(RedisOptionRule.HOST.key()));
        redisConfiguration.setPort(Integer.valueOf(redisOption.get(RedisOptionRule.PORT.key())));
        redisConfiguration.setMode(redisOption.get(RedisOptionRule.MODE.key()));
        redisConfiguration.setAuth(redisOption.get(RedisOptionRule.AUTH.key()));
        redisConfiguration.setkey(redisOption.get(RedisOptionRule.KEY.key()));
        redisConfiguration.setData_type(redisOption.get(RedisOptionRule.DATA_TYPE.key()));

        return redisConfiguration;
    }
}
