package org.wso2.carbon.device.mgt.ios.payload.util;

import org.wso2.carbon.context.PrivilegedCarbonContext;

import java.util.UUID;

public class OperationUtils {

    private static final int REMOVE_APP_WHEN_MDM_PROFILE_IS_REMOVED = 1;
    private static final int PREVENT_BACKUP_OF_APP_DATA = 4;
    private static final int NO_MANGED_DATA = 0;

    public static int mapManagementFlagsForApplications(boolean removeAppUponMDMProfileRemoval,
                                                 boolean preventBackupOfAppData) {

        // 1 — Remove app when MDM profile is removed.
        // 4 — Prevent backup of the app data.
        // If both available perform bitwise OR.

        if (removeAppUponMDMProfileRemoval && preventBackupOfAppData) {
            return REMOVE_APP_WHEN_MDM_PROFILE_IS_REMOVED | PREVENT_BACKUP_OF_APP_DATA;
        } else if(removeAppUponMDMProfileRemoval) {
            return REMOVE_APP_WHEN_MDM_PROFILE_IS_REMOVED;
        } else if(preventBackupOfAppData) {
            return PREVENT_BACKUP_OF_APP_DATA;
        }

        return NO_MANGED_DATA;
    }

    public static String generateRandomUUID() {
        return UUID.randomUUID().toString();
    }

    //TODO implement this
    public static String getTenantNameFromOperationID() {
        return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    }

    //TODO implement this
    public static boolean isPayloadRemoveDisallowedForTenant() {
        return false;
    }
}
