from ..baseElement import BaseElement
from ...contextHolder import ContextHolder
from ...log.result import Result
from ...log.resultList import ResultList
from ...error import IllegalElementActionException

__author__ = 'nprikazchikov'

logger = ContextHolder.get_logger()


class Checkbox(BaseElement):
    VALUE_ON = "on"
    VALUE_OFF = "off"

    def __init__(self, *args, **kwargs):
        BaseElement.__init__(self, *args, **kwargs)
        self._type = "checkbox"

    def __check_value(self, value):
        if isinstance(value, bool):
            value = self.VALUE_ON if value else self.VALUE_OFF

        if not (value == self.VALUE_ON or value == self.VALUE_OFF):
            IllegalElementActionException(
                "Unexpected checkbox value. Please use {} or {} constants from"
                " checkbox class or bool".format(self.VALUE_ON, self.VALUE_OFF)
            )
        return value

    def get_value(self):
        return self.VALUE_ON \
            if self.get_element().is_selected() \
            else self.VALUE_OFF

    def set_value(self, value):
        value = self.__check_value(value)

        res = ResultList("Set checkbox [{}] to: [{}]".format(
            self._element_name, value
        ))
        if not self.get_value() == value:
            res.push(self.click())
        else:
            res.push(
                Result(
                    "The checkbox [{}] already set to: [{}]".format(
                        self._element_name,
                        value
                    )
                )
            )
        return res

    def verify_value(self, value):
        value = self.__check_value(value)
        return BaseElement.verify_value(self, value)

1a8c309aae493db666905b232319794d93dbbd06
<mask token>


class Checkbox(BaseElement):
    <mask token>
    <mask token>
    <mask token>

    def __check_value(self, value):
        if isinstance(value, bool):
            value = self.VALUE_ON if value else self.VALUE_OFF
        if not (value == self.VALUE_ON or value == self.VALUE_OFF):
            IllegalElementActionException(
                'Unexpected checkbox value. Please use {} or {} constants from checkbox class or bool'
                .format(self.VALUE_ON, self.VALUE_OFF))
        return value

    def get_value(self):
        return self.VALUE_ON if self.get_element().is_selected(
            ) else self.VALUE_OFF
    <mask token>

    def verify_value(self, value):
        value = self.__check_value(value)
        return BaseElement.verify_value(self, value)

<mask token>


class Checkbox(BaseElement):
    <mask token>
    <mask token>

    def __init__(self, *args, **kwargs):
        BaseElement.__init__(self, *args, **kwargs)
        self._type = 'checkbox'

    def __check_value(self, value):
        if isinstance(value, bool):
            value = self.VALUE_ON if value else self.VALUE_OFF
        if not (value == self.VALUE_ON or value == self.VALUE_OFF):
            IllegalElementActionException(
                'Unexpected checkbox value. Please use {} or {} constants from checkbox class or bool'
                .format(self.VALUE_ON, self.VALUE_OFF))
        return value

    def get_value(self):
        return self.VALUE_ON if self.get_element().is_selected(
            ) else self.VALUE_OFF
    <mask token>

    def verify_value(self, value):
        value = self.__check_value(value)
        return BaseElement.verify_value(self, value)

<mask token>


class Checkbox(BaseElement):
    VALUE_ON = 'on'
    VALUE_OFF = 'off'

    def __init__(self, *args, **kwargs):
        BaseElement.__init__(self, *args, **kwargs)
        self._type = 'checkbox'

    def __check_value(self, value):
        if isinstance(value, bool):
            value = self.VALUE_ON if value else self.VALUE_OFF
        if not (value == self.VALUE_ON or value == self.VALUE_OFF):
            IllegalElementActionException(
                'Unexpected checkbox value. Please use {} or {} constants from checkbox class or bool'
                .format(self.VALUE_ON, self.VALUE_OFF))
        return value

    def get_value(self):
        return self.VALUE_ON if self.get_element().is_selected(
            ) else self.VALUE_OFF

    def set_value(self, value):
        value = self.__check_value(value)
        res = ResultList('Set checkbox [{}] to: [{}]'.format(self.
            _element_name, value))
        if not self.get_value() == value:
            res.push(self.click())
        else:
            res.push(Result('The checkbox [{}] already set to: [{}]'.format
                (self._element_name, value)))
        return res

    def verify_value(self, value):
        value = self.__check_value(value)
        return BaseElement.verify_value(self, value)

<mask token>
__author__ = 'nprikazchikov'
logger = ContextHolder.get_logger()


class Checkbox(BaseElement):
    VALUE_ON = 'on'
    VALUE_OFF = 'off'

    def __init__(self, *args, **kwargs):
        BaseElement.__init__(self, *args, **kwargs)
        self._type = 'checkbox'

    def __check_value(self, value):
        if isinstance(value, bool):
            value = self.VALUE_ON if value else self.VALUE_OFF
        if not (value == self.VALUE_ON or value == self.VALUE_OFF):
            IllegalElementActionException(
                'Unexpected checkbox value. Please use {} or {} constants from checkbox class or bool'
                .format(self.VALUE_ON, self.VALUE_OFF))
        return value

    def get_value(self):
        return self.VALUE_ON if self.get_element().is_selected(
            ) else self.VALUE_OFF

    def set_value(self, value):
        value = self.__check_value(value)
        res = ResultList('Set checkbox [{}] to: [{}]'.format(self.
            _element_name, value))
        if not self.get_value() == value:
            res.push(self.click())
        else:
            res.push(Result('The checkbox [{}] already set to: [{}]'.format
                (self._element_name, value)))
        return res

    def verify_value(self, value):
        value = self.__check_value(value)
        return BaseElement.verify_value(self, value)

from ..baseElement import BaseElement
from ...contextHolder import ContextHolder
from ...log.result import Result
from ...log.resultList import ResultList
from ...error import IllegalElementActionException

__author__ = 'nprikazchikov'

logger = ContextHolder.get_logger()


class Checkbox(BaseElement):
    VALUE_ON = "on"
    VALUE_OFF = "off"

    def __init__(self, *args, **kwargs):
        BaseElement.__init__(self, *args, **kwargs)
        self._type = "checkbox"

    def __check_value(self, value):
        if isinstance(value, bool):
            value = self.VALUE_ON if value else self.VALUE_OFF

        if not (value == self.VALUE_ON or value == self.VALUE_OFF):
            IllegalElementActionException(
                "Unexpected checkbox value. Please use {} or {} constants from"
                " checkbox class or bool".format(self.VALUE_ON, self.VALUE_OFF)
            )
        return value

    def get_value(self):
        return self.VALUE_ON \
            if self.get_element().is_selected() \
            else self.VALUE_OFF

    def set_value(self, value):
        value = self.__check_value(value)

        res = ResultList("Set checkbox [{}] to: [{}]".format(
            self._element_name, value
        ))
        if not self.get_value() == value:
            res.push(self.click())
        else:
            res.push(
                Result(
                    "The checkbox [{}] already set to: [{}]".format(
                        self._element_name,
                        value
                    )
                )
            )
        return res

    def verify_value(self, value):
        value = self.__check_value(value)
        return BaseElement.verify_value(self, value)
