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

import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class FtpAConfiguration {

    public static FtpConfiguration getConfiguration(Map<String, String> ftpOption) {

        if (!ftpOption.containsKey(FtpOptionRule.HOST.key())) {
            throw new IllegalArgumentException(
                    "FtpRedshift datasource host is null, please check your config");
        }
        if (!ftpOption.containsKey(FtpOptionRule.PORT.key())) {
            throw new IllegalArgumentException(
                    "FtpRedshift datasource port is null, please check your config");
        }
        if (!ftpOption.containsKey(FtpOptionRule.USER.key())) {
            throw new IllegalArgumentException(
                    "FtpRedshift datasource username is null, please check your config");
        }
        if (!ftpOption.containsKey(FtpOptionRule.PASSWORD.key())) {
            throw new IllegalArgumentException(
                    "FtpRedshift datasource password is null, please check your config");
        }
        if (!ftpOption.containsKey(FtpOptionRule.PATH.key())) {
            throw new IllegalArgumentException(
                    "FtpRedshift datasource path is null, please check your config");
        }
        if (!ftpOption.containsKey(FtpOptionRule.FILE_FORMAT_TYPE.key())) {
            throw new IllegalArgumentException(
                    "FtpRedshift datasource file_format_type is null, please check your config");
        }
        FtpConfiguration ftpConfiguration = new FtpConfiguration();
        ftpConfiguration.setHost(ftpOption.get(FtpOptionRule.HOST.key()));
        ftpConfiguration.setPort(ftpOption.get(FtpOptionRule.PORT.key()));
        ftpConfiguration.setUser(ftpOption.get(FtpOptionRule.USER.key()));
        ftpConfiguration.setPassword(ftpOption.get(FtpOptionRule.PASSWORD.key()));
        ftpConfiguration.setPath(ftpOption.get(FtpOptionRule.PATH.key()));
        ftpConfiguration.setType(ftpOption.get(FtpOptionRule.FILE_FORMAT_TYPE.key()));

        return ftpConfiguration;
    }
}
