#
# OMNIVORE CONFIDENTIAL
# __________________
#
#  [2013] - [2020] Omnivore Technologies
#  All Rights Reserved.
#
# NOTICE:  All information contained herein is, and remains
# the property of Omnivore Technologies and its suppliers,
# if any.  The intellectual and technical concepts contained
# herein are proprietary to Omnivore Technologies
# and its suppliers and may be covered by U.S. and Foreign Patents,
# patents in process, and are protected by trade secret or copyright law.
# Dissemination of this information or reproduction of this material
# is strictly forbidden unless prior written permission is obtained
# from Omnivore Technologies.
#
import logging

from agent_common.config import Config

from agent_updater.config_migration.config_migration import (
    ALOHA_CLIENT_SECTION,
    ConfigMigration,
    restricted_to,
)

logger = logging.getLogger(__name__)

MIGRATION_VERSION = '19.7.17'
CLASS_NAME = 'ConfigMigration190717'


class ConfigMigration190717(ConfigMigration):

    @restricted_to(Config.POS_TYPE_ALOHA)
    def up(self):
        """
        Ensure Aloha's ExposeOrderModes stays `False` for existing locations.
        """
        # These "gets" fall back to default values if not explicitly defined
        expose_order_modes_directive = "ExposeOrderModes"
        expose_order_modes_value = self._config.get_undefaulted_raw_value(ALOHA_CLIENT_SECTION, expose_order_modes_directive)
        # These "sets" ignore defaults, ensuring the value appears in the INI file
        if expose_order_modes_value is None:
            logger.info(
                "{directive} is unset; setting '{directive} = False'".format(directive=expose_order_modes_directive),
            )
            self._config.set_value(
                self._config.FILE_GENERAL,
                ALOHA_CLIENT_SECTION,
                expose_order_modes_directive,
                "False",
            )
        else:
            logger.info("{} is set to '{}'; skipping config migration".format(
                expose_order_modes_directive,
                expose_order_modes_value),
            )
