import { UpdateType } from "./UpdateInfo";

/**
 * Info about observed update.
 *
 * Returned @see updateResult corresponds to these data:
 * - {@link UpdateResult.SUCCESS}:
 *     @see failureReason is null
 * - {@link UpdateResult.PARTIAL_SUCCESS}:
 *     @see failureReason is not null
 *     and @see updatedApps is not empty
 * - {@link UpdateResult.FAILURE}:
 *     and @see failureReason is not null
 *     and @see updatedApps is empty
 *
 * Partially successful update can happen when an error occurs while storing the suggestions locally.
 * In such case, suggestions for only a fraction of apps were stored.
 */
export interface ObservedUpdateInfo {
    /** Result of the update. */
    readonly updateResult: UpdateResult;
    /** Type of update performed. */
    readonly updateType: UpdateType;
    /** List of apps that were checked in the update. */
    readonly checkedApps: [string];
    /** List of apps that were successfully updated in the update. */
    readonly updatedApps: [string];
    /** String representation of an error that occurred during processing of the update. */
    readonly failureReason?: string;
}

/** Result of an update. */
export enum UpdateResult {
    /**
     * Successful update.
     *
     * All apps were successfully updated without any error.
     */
    SUCCESS = "SUCCESS",
    /**
     * Partially successful update.
     *
     * Some apps were successfully updated but not all of them.
     * Some apps couldn't be successfully updated for some reason.
     */
    PARTIAL_SUCCESS = "PARTIAL_SUCCESS",
    /**
     * Failure.
     *
     * Update failed for some reason.
     */
    FAILURE = "FAILURE"
}