from abc import ABC, abstractmethod
from src.items.exceptions.invalid_quality_value import InvalidQualityValue
from src.items.helpers.constants import MAX_QUALITY_DEFAULT_VALUE, MIN_QUALITY_DEFAULT_VALUE


class Item(ABC):

    def __init__(self, name: str, sell_in: int, quality: int):
        self._name = name
        self._sell_in = sell_in
        self._quality = quality

    def __repr__(self):
        return "%s, %s, %s" % (self._name, self._sell_in, self._quality)

    def get_sell_in(self):
        return self._sell_in

    def get_quality(self):
        return self._quality

    @abstractmethod
    def update_quality(self):
        pass

    def is_quality_valid_after_addition(self, value):
        return self.get_quality() + value <= MAX_QUALITY_DEFAULT_VALUE

    def is_quality_valid_after_subtraction(self, value):
        return self.get_quality() - value >= MIN_QUALITY_DEFAULT_VALUE

    def is_item_sale_date_passed(self):
        return self.get_sell_in() <= 0

    def is_valid_quality(self, quality_value):
        if quality_value >= MIN_QUALITY_DEFAULT_VALUE and quality_value <= MAX_QUALITY_DEFAULT_VALUE:
            return quality_value
        raise InvalidQualityValue('Quality value must be between 0 and 50')
