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

/**
 * SSH compressions.
 *
 * @author Alex Usun
 */
public class Compressions {

    public static final ComponentCompressionFactory.Entry NONE = ComponentCompressionFactory.Entry.NONE;

    /**
     * The 'zlib' compression algorithm.
     */
    public static final ComponentCompressionFactory.Entry ZLIB = new ComponentCompressionFactory.Entry("zlib") {

        @Override
        public Compression clientToServerCompressionFor(CompressionFactory.Mode mode) {
            return mode == CompressionFactory.Mode.COMPRESSION ? new ZlibCompressor() : new ZlibDecompressor();
        }

        @Override
        public Compression serverToClientCompressionFor(CompressionFactory.Mode mode) {
            return mode == CompressionFactory.Mode.COMPRESSION ? new ZlibCompressor() : new ZlibDecompressor();
        }
    };

    public static final ComponentCompressionFactory.Entry[] ALL = { NONE, ZLIB };

    /**
     * Setups required algorithms.
     *
     * @param factory a factory
     *
     * @return a factory
     */
    public static ComponentCompressionFactory initRequired(ComponentCompressionFactory factory) {
        factory.set(ComponentCompressionFactory.Entry.NONE);

        return factory;
    }

    /**
     * Setups optional algorithms.
     *
     * @param factory a factory
     *
     * @return a factory
     */
    public static ComponentCompressionFactory initOptional(ComponentCompressionFactory factory) {
        factory.set(ZLIB);

        return factory;
    }

    /**
     * Setups all implemented algorithms.
     *
     * @param factory a factory
     *
     * @return a factory
     */
    public static ComponentCompressionFactory initAll(ComponentCompressionFactory factory) {
        return initOptional(initRequired(factory));
    }

    public static ComponentCompressionFactory initAllClient(ComponentCompressionFactory factory) {
        return factory.set(ComponentCompressionFactory.Entry.NONE, ZLIB);
    }

    private Compressions() {
        //empty
    }
}
