#
# 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 = '20.2.19'
CLASS_NAME = 'ConfigMigration200219'


class ConfigMigration200219(ConfigMigration):
    
    @restricted_to(Config.POS_TYPE_ALOHA)
    def up(self):
        """
        Set [Aloha]EnableItemOrderModes to `False` for all existing locations in order to maintain
        existing behavior. All new locations default to `True`.
        """
        directive = "EnableItemOrderModes"
        directive_value = self._config.get_undefaulted_raw_value(ALOHA_CLIENT_SECTION, directive)

        # The "set" method ignores defaults, ensuring the value appears in the INI file
        if directive_value is None:
            logger.info(
                "{directive} is unset; setting '{directive} = False'".format(directive=directive),
            )
            self._config.set_value(
                self._config.FILE_GENERAL,
                ALOHA_CLIENT_SECTION,
                directive,
                "False",
            )
        else:
            logger.info("{directive} is set to '{directive_value}'; skipping config migration".format(
                directive=directive,
                directive_value=directive_value,
            ))

