package com.atlassian.bitbucket.installer;

import java.util.Optional;

/**
 * The mode the installer is running in.
 */
public enum InstallationType {
    /**
     * Install of a server Bitbucket instance.
     */
    INSTALL("installer-type-install", false),

    /**
     * Upgrade of an existing Bitbucket server instance.
     */
    UPGRADE("installer-type-upgrade", true),

    /**
     * Install of a Bitbucket Data Center instance.
     */
    DATA_CENTER_INSTALL("installer-type-data-center-install", false),

    /**
     * Upgrade of an existing Bitbucket Data Center instance.
     */
    DATA_CENTER_UPGRADE("installer-type-data-center-upgrade", true),

    /**
     * Install of a Bitbucket mirror instance.
     */
    MIRROR_INSTALL("installer-type-mirror-install", false),

    /**
     * Upgrade of an existing Bitbucket mirror instance.
     */
    MIRROR_UPGRADE("installer-type-mirror-upgrade", true);

    private final String eventName;
    private final boolean upgrade;

    InstallationType(String eventName, boolean upgrade) {
        this.eventName = eventName;
        this.upgrade = upgrade;
    }

    public static Optional<InstallationType> parse(String typeString) {
        for (InstallationType type : InstallationType.values()) {
            if (type.name().equalsIgnoreCase(typeString)) {
                return Optional.of(type);
            }
        }
        return Optional.empty();
    }

    public String getEventName() {
        return eventName;
    }

    public boolean isUpgrade() {
        return upgrade;
    }
}
