package com.jscape.inet.ssh.protocol.v2.marshaling.algorithms;

import com.jscape.util.SuppressObfuscation;

import java.util.List;

/**
 * A SSH compression factory.
 *
 * @author Alex Usun
 */
public interface CompressionFactory {

    /**
     * Returns supported compression algorithms.
     *
     * @return supported compression algorithms
     */
    List<String> compressions();

    /**
     * Returns a compression operation for client-server direction.
     *
     * @param name a SSH algorithm name
     * @param mode an algorithm mode
     *
     * @return a compression operation
     *
     * @throws OperationException if an error occurs
     */
    Compression clientToServerCompressionFor(String name, Mode mode)
            throws OperationException;

    /**
     * Returns a compression operation for server-client direction.
     *
     * @param name a SSH algorithm name
     * @param mode an algorithm mode
     *
     * @return a compression operation
     *
     * @throws OperationException if an error occurs
     */
    Compression serverToClientCompressionFor(String name, Mode mode)
            throws OperationException;

    /**
     * Represents an operation error.
     */
    @SuppressObfuscation
    class OperationException
            extends Exception {

        public OperationException() {
        }

        public OperationException(String message) {
            super(message);
        }

        public OperationException(String message, Throwable cause) {
            super(message, cause);
        }

        public OperationException(Throwable cause) {
            super(cause.getMessage() != null ? cause.getMessage() : cause.toString(), cause);
        }
    }

    /**
     * Algorithm mode.
     */
    enum Mode {

        COMPRESSION,
        DECOMPRESSION
    }
}
