package com.jscape.inet.ssh.protocol.v2.authentication;

import com.jscape.inet.ssh.protocol.v2.marshaling.MessageCodec;
import com.jscape.inet.ssh.protocol.v2.messages.UserAuthInfoRequestPrompt;

import java.util.Arrays;
import java.util.List;

import static com.jscape.util.Parameters.assertNotNull;

/**
 * Represents a SSH 'keyboard-interactive' authentication operation which sends pre-defined responses.
 *
 * @author Alex Usun
 */
public class KeyboardInteractivePredefinedClientAuthentication
        extends AbstractKeyboardInteractiveClientAuthentication {

    private final List<String> responses;

    public static KeyboardInteractivePredefinedClientAuthentication defaultAuthentication(String username, List<String> responses) {
        return new KeyboardInteractivePredefinedClientAuthentication(KeyboardInteractiveMessages.defaultMessages(), username, responses);
    }

    /**
     * Creates a new operation instance.
     *
     * @param username an username
     * @param responses responses
     */
    public KeyboardInteractivePredefinedClientAuthentication(MessageCodec.Factory codecFactory, String username, List<String> responses) {
        super(codecFactory, username);

        assertNotNull(responses);
        this.responses = responses;
    }

    /**
     * Creates a new operation instance.
     *
     * @param username an username
     * @param responses responses
     */
    public KeyboardInteractivePredefinedClientAuthentication(MessageCodec.Factory codecFactory, String username, String... responses) {
        this(codecFactory, username, Arrays.<String>asList(responses));
    }

    @Override
    protected List<String> responsesFor(String name, String instruction, List<UserAuthInfoRequestPrompt> prompts) {
        return this.responses;
    }
}
