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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.ios.api.utils.util.Message;
import org.wso2.carbon.device.mgt.ios.apns.exception.APNSException;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;

public class PolicyUtils {

    private static final Log log = LogFactory.getLog(PolicyUtils.class);

    public void enforceEffectivePolicy (String deviceID) throws APNSException {

        DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
        deviceIdentifier.setId(deviceID);
        deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS);

        try {
            PolicyManagerService policyManagerService = IOSServiceUtils.getPolicyManagerService();
            policyManagerService.getEffectivePolicy(deviceIdentifier);

            //TODO for now just send push notification here.
            //PushNotificationSenderUtils pushNotificationSenderUtils = new PushNotificationSenderUtils();
            //pushNotificationSenderUtils.contactAPNS(deviceIdentifier, new Message());
        } catch (PolicyManagementException e) {
            log.error("Error fetching effective policy from device " + deviceID, e);
        }

    }
}
