package com.charlesdream.office.word.enums;

import com.charlesdream.office.BaseEnum;

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

/**
 * Specifies a type of mail merge document.
 * <p>
 *
 * @author Charles Cui on 3/4/16.
 * @since 1.0
 */
public enum WdMailMergeMainDocType implements BaseEnum {
    /**
     * Catalog.
     *
     * @since 1.0
     */
    wdCatalog(3),

    /**
     * Directory.
     *
     * @since 1.0
     */
    wdDirectory(3),

    /**
     * E-mail message.
     *
     * @since 1.0
     */
    wdEMail(4),

    /**
     * Envelope.
     *
     * @since 1.0
     */
    wdEnvelopes(2),

    /**
     * Fax.
     *
     * @since 1.0
     */
    wdFax(5),

    /**
     * Form letter.
     *
     * @since 1.0
     */
    wdFormLetters(0),

    /**
     * Mailing label.
     *
     * @since 1.0
     */
    wdMailingLabels(1),

    /**
     * Not a merge document.
     *
     * @since 1.0
     */
    wdNotAMergeDocument(-1);


    private static final Map<Integer, WdMailMergeMainDocType> lookup;

    static {
        lookup = new HashMap<>();

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


    private final int value;

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