# ------------------------------------------------------------------------------
# Class to load settings from the displaysettings.json file
# ------------------------------------------------------------------------------

import json
import os
from robot.api import logger


class DisplaySettings(object):
    """
    Class that loads and exposes the display settings from the displaysettings.json file
    """
    __json_data = None
    __width = None
    __height = None
    __depth = None

    @staticmethod
    def __get_json_value(key):
        if DisplaySettings.__json_data is None:
            filename = os.path.abspath(os.path.join(os.path.dirname(__file__), 'displaysettings.json'))
            with open(filename, 'r') as json_file:
                raw_data = json_file.read()
                DisplaySettings.__json_data = json.loads(raw_data)
                logger.info("Display settings json file loaded")
        return DisplaySettings.__json_data[key]

    @staticmethod
    def get_width():
        if DisplaySettings.__width is None:
            result = DisplaySettings.__get_json_value('width')
            DisplaySettings.__width = int(result)
        logger.info("display width = %s" % str(DisplaySettings.__width))
        return DisplaySettings.__width

    @staticmethod
    def get_height():
        if DisplaySettings.__height is None:
            result = DisplaySettings.__get_json_value('height')
            DisplaySettings.__height = int(result)
        logger.info("display height = %s" % str(DisplaySettings.__height))
        return DisplaySettings.__height

    @staticmethod
    def get_depth():
        if DisplaySettings.__depth is None:
            result = DisplaySettings.__get_json_value('depth')
            DisplaySettings.__depth = int(result)
        logger.info("display depth = %s" % str(DisplaySettings.__depth))
        return DisplaySettings.__depth

    @staticmethod
    def set_width(width):
        DisplaySettings.__width = width

    @staticmethod
    def set_height(height):
        DisplaySettings.__height = height

    @staticmethod
    def set_depth(depth):
        DisplaySettings.__depth = depth
