package com.charlesdream.office.word.enums;

import com.charlesdream.office.BaseEnum;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * Specifies how text is laid out in the layout mode for the current document.
 * <p>
 *
 * @author Charles Cui on 3/4/16.
 * @since 1.0
 */
public enum WdLayoutMode implements BaseEnum {
    /**
     * No grid is used to lay out text.
     *
     * @since 1.0
     */
    wdLayoutModeDefault(0),

    /**
     * Text is laid out on a grid; the user specifies the number of lines and the number of characters per line. As the user types, Microsoft Word automatically aligns characters with gridlines.
     *
     * @since 1.0
     */
    wdLayoutModeGenko(3),

    /**
     * Text is laid out on a grid; the user specifies the number of lines and the number of characters per line. As the user types, Microsoft Word doesn't automatically align characters with gridlines.
     *
     * @since 1.0
     */
    wdLayoutModeGrid(1),

    /**
     * Text is laid out on a grid; the user specifies the number of lines, but not the number of characters per line.
     *
     * @since 1.0
     */
    wdLayoutModeLineGrid(2);


    private static final Map<Integer, WdLayoutMode> lookup;

    static {
        lookup = new HashMap<>();

        for (WdLayoutMode e : EnumSet.allOf(WdLayoutMode.class)) {
            lookup.put(e.value(), e);
        }
    }


    private final int value;

    WdLayoutMode(int value) {
        this.value = value;
    }


    /**
     * Find the enum type by its value.
     *
     * @param value The enum value.
     * @return The enum type, or null if this enum value does not exists.
     * @since 1.0
     */
    public static WdLayoutMode find(int value) {
        WdLayoutMode result = lookup.get(value);

        return result;
    }

    /**
     * Find the enum type by its value, with the default value.
     *
     * @param value        The enum value.
     * @param defaultValue The default return value if the enum value does not exists.
     * @return The enum type, or the default value if this enum value does not exists.
     * @since 1.0
     */
    public static WdLayoutMode find(int value, WdLayoutMode defaultValue) {
        WdLayoutMode result = WdLayoutMode.find(value);

        if (result == null) {
            result = defaultValue;
        }

        return result;
    }

    /**
     * Get the value of a enum type.
     *
     * @return The value of a enum type.
     * @since 1.0
     */
    public int value() {
        return this.value;
    }
}
