/*
 * 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.rabbitmq;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class RabbitAConfiguration {

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

        if (!redisOption.containsKey(RabbitmqOptionRule.HOST.key())) {
            throw new IllegalArgumentException(
                    "redis datasource host is null, please check your config");
        }
        if (!redisOption.containsKey(RabbitmqOptionRule.PORT.key())) {
            throw new IllegalArgumentException(
                    "redis datasource port is null, please check your config");
        }
        if (!redisOption.containsKey(RabbitmqOptionRule.USERNAME.key())) {
            throw new IllegalArgumentException(
                    "redis datasource username is null, please check your config");
        }
        if (!redisOption.containsKey(RabbitmqOptionRule.PASSWORD.key())) {
            throw new IllegalArgumentException(
                    "redis datasource password is null, please check your config");
        }
        if (!redisOption.containsKey(RabbitmqOptionRule.VIRTUAL_HOST.key())) {
            throw new IllegalArgumentException(
                    "redis datasource virtual_host is null, please check your config");
        }
        if (!redisOption.containsKey(RabbitmqOptionRule.QUEUE_NAME.key())) {
            throw new IllegalArgumentException(
                    "redis datasource queue_name is null, please check your config");
        }
        if (!redisOption.containsKey(RabbitmqOptionRule.URL.key())) {
            throw new IllegalArgumentException(
                    "redis datasource url is null, please check your config");
        }
        RabbitConfiguration redisConfiguration = new RabbitConfiguration();
        redisConfiguration.setHost(redisOption.get(RabbitmqOptionRule.HOST.key()));
        redisConfiguration.setPort(Integer.valueOf(redisOption.get(RabbitmqOptionRule.PORT.key())));
        redisConfiguration.setUsername(redisOption.get(RabbitmqOptionRule.USERNAME.key()));
        redisConfiguration.setPassword(redisOption.get(RabbitmqOptionRule.PASSWORD.key()));
        redisConfiguration.setVirtualHost(redisOption.get(RabbitmqOptionRule.VIRTUAL_HOST.key()));
        redisConfiguration.setQueueName(redisOption.get(RabbitmqOptionRule.QUEUE_NAME.key()));
        redisConfiguration.setUri(redisOption.get(RabbitmqOptionRule.URL.key()));

        return redisConfiguration;
    }
}
