

package com.microsoft.azure.storage.table;

/**
 * Reserved for internal use. An enumeration type which represents the type of operation a {@link TableOperation}
 * represents.
 */
enum TableOperationType {

    /**
     * The table operation creates an entity which does not yet exist.
     */
    INSERT,

    /**
     * The table operation delete an existing entity.
     */
    DELETE,

    /**
     * The table operation replaces an existing entity.
     */
    REPLACE,

    /**
     * The table operation retrieves an existing entity.
     */
    RETRIEVE,

    /**
     * The table operation updates an existing entity.
     */
    MERGE,

    /**
     * The table operation replaces an existing entity or inserts it.
     */
    INSERT_OR_REPLACE,

    /**
     * The table operation updates an existing entity or inserts it.
     */
    INSERT_OR_MERGE;

    /**
     * Gets the {@link TableUpdateType} associated the operation type, if applicable. Applies to
     * {@link #INSERT_OR_MERGE} and {@link #INSERT_OR_REPLACE} values.
     * 
     * @return
     *         The applicable {@link TableUpdateType}, or <code>null</code>.
     */
    protected TableUpdateType getUpdateType() {
        if (this == INSERT_OR_MERGE) {
            return TableUpdateType.MERGE;
        }
        else if (this == INSERT_OR_REPLACE) {
            return TableUpdateType.REPLACE;
        }
        else {
            return null;
        }
    }
}
