package com.avg.zaap.crashlibrary.publish.packer;

import com.avg.zaap.crashlibrary.core.logger.ILogger;

/**
 * Interface for unPacking files.
 * <p>
 * Created by marek.osvald on 19.4.2016.
 */
public interface IBinUnPacker {

    /**
     * Set the destination to store results.
     *
     * @param destinationPath where the bin file will be stored.
     * @throws BinUnPackerException when some problems occurs when setting destination.
     */
    void setDestinationPath(String destinationPath) throws BinUnPackerException;

    /**
     * Set logger for logging according to user of this implementation.
     * @param logger to be set and used for logging.
     */
    void setLogger(ILogger logger);

    /**
     * Grab file from given file path and decode it and store it to predefined location (see constructors).
     *
     * @param filePath  of source file, consists of absolute path.
     * @param flatMode  default value is false, if is true, then all files will be extracted in root folder (name of given {@link BinUnPacker#EXT_RESULT} file).
     * @param forceMode override existing files, if is set to false, will rename new files with counter prefix.
     * @throws BinUnPackerException when some error occurs.
     */
    void unpack(String filePath, boolean flatMode, boolean forceMode) throws BinUnPackerException;

    /**
     * Prints all files stored in given file.
     *
     * @param filePath to packed .bp file.
     * @throws BinUnPackerException when some error occurs.
     */
    void list(String filePath) throws BinUnPackerException;

    /**
     * Custom exception for local usage.
     */
    class BinUnPackerException extends Exception {
        /**
         * Default constructor. Calls {@link RuntimeException} constructor.
         */
        @SuppressWarnings("unused")
        public BinUnPackerException() {
            super();
        }

        /**
         * Parametric constructor. Initializes the exception with a detailed message.
         *
         * @param detailMessage detailed message to initialize the exception with
         */
        @SuppressWarnings("SameParameterValue")
        public BinUnPackerException(String detailMessage) {
            super(detailMessage);
        }

        /**
         * Parametric constructor. Initializes the exception with a detailed message and a throwable
         * instance.
         *
         * @param detailMessage detailed message to initialize the exception with
         * @param throwable     throwable instance to initialize the exception with
         */
        public BinUnPackerException(String detailMessage, Throwable throwable) {
            super(detailMessage, throwable);
        }

        /**
         * Parametric constructor. Initializes the exception with a throwable instance.
         *
         * @param throwable throwable instance to initialize the exception with
         */
        public BinUnPackerException(Throwable throwable) {
            super(throwable);
        }
    }
}
