package com.charlesdream.office.word.enums;

import com.charlesdream.office.BaseEnum;

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

/**
 * Specifies the reading order for the specified object.
 * <p>
 * Version Added: Word 2007
 * <p>
 *
 * @author Charles Cui on 3/5/2016.
 * @since 1.0
 */
public enum XlReadingOrder implements BaseEnum {

    /**
     * According to context.
     *
     * @since 1.0
     */
    xlContext(-5002),

    /**
     * Left-to-right.
     *
     * @since 1.0
     */
    xlLTR(-5003),

    /**
     * Right-to-left.
     *
     * @since 1.0
     */
    xlRTL(-5004);


    private static final Map<Integer, XlReadingOrder> lookup;

    static {
        lookup = new HashMap<>();

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


    private final int value;

    XlReadingOrder(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 XlReadingOrder find(int value) {
        XlReadingOrder 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 XlReadingOrder find(int value, XlReadingOrder defaultValue) {
        XlReadingOrder result = XlReadingOrder.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;
    }
}
