
# Property. getter, setter.
'''
class BandAccount:
    def __init__(self, name, balance) -> None:
        self.name = name
        self.__balance = balance
        
    def get_balance(self):
        return self.__balance
    
    def set_balance(self, value):
        if not isinstance(value, (int, float)):
            raise ValueError("Баланс должен быть числом")
        self.__balance = value
'''

'''
class BankAccount:
    def __init__(self, name, balance) -> None:
        self.name = name
        self.__balance = balance
        
    def get_balance(self):
        return self.__balance
    
    def set_balance(self, value):
        if not isinstance(value, (int, float)):
            raise ValueError("Баланс должен быть числом")
        self.__balance = value

    def delete_balance(self):
        del self.__balance

    balance = property(fget=get_balance, fset=set_balance, fdel=delete_balance)
'''

class BankAccount:
    def __init__(self, name, balance) -> None:
        self.name = name
        self.__balance = balance
        
    def get_balance(self):
        return self.__balance
    
    def set_balance(self, value):
        if not isinstance(value, (int, float)):
            raise ValueError("Баланс должен быть числом")
        self.__balance = value

    def delete_balance(self):
        del self.__balance

    balance = property(fget=get_balance, fset=set_balance, fdel=delete_balance)
    

class BankAccount:
    def __init__(self, account_number, balance) -> None:
        self._account_number = account_number
        self._balance = balance

    def get_account_number(self):
        return self._account_number
    
    def get_balance(self):
        return self._balance
    
    def set_balance(self, value):
        if not isinstance(value, (int, float)):
            raise ValueError("ErrorValue!!!")
        self._balance = value

        
class Employee:
    def __init__(self, name, salary) -> None:
        self.__name = name
        self.__salary = salary

    def __get_name(self):
        return self.__name

    def __get_salary(self):
        return self.__salary
    
    def __set_salary(self, value):
        if not isinstance(value, (int, float)) or (value < 0):
            print(f"ErrorValue:{value}")
            return
        self.__salary = value

    title = property(fget=__get_name)

    reward = property(fget=__get_salary, fset=__set_salary)


class UserMail:
    def __init__(self, login, email: str):
        self.login = login
        self.__email = email

    def get_email(self):
        return self.__email
    
    def set_email(self, email):
        if not isinstance(email, str):
            print(f"ErrorMail:{email}")
            return
        if email.count('@') == 1 and (email.rfind('@') < email.rfind('.')):
            self.__email = email
        else:
            print(f"ErrorMail:{email}")
            return

    email = property(fget=get_email, fset=set_email)




def main():
    '''
    acc = BandAccount('Ivan', 200)
    acc.balance = 400
    print(acc.balance)
    '''

    '''
    employee = Employee("John Doe", 50000)
    assert employee.title == "John Doe"
    assert employee._Employee__name == "John Doe"
    assert isinstance(employee, Employee)
    assert isinstance(type(employee).title, property), 'Вы не создали property title'
    assert isinstance(type(employee).reward, property), 'Вы не создали property reward'

    assert employee.reward == 50000
    employee.reward = -100  # ErrorValue:-100

    employee.reward = 1.5
    assert employee.reward == 1.5

    employee.reward = 70000
    assert employee.reward == 70000
    employee.reward = 'hello'  # Печатает ErrorValue:hello
    employee.reward = '777'  # Печатает ErrorValue:777
    employee.reward = [1, 2]  # Печатает ErrorValue:[1, 2]
    assert employee.reward == 70000
    employee._Employee__set_salary(55000)
    assert employee._Employee__get_salary() == 55000
    '''

    jim = UserMail("aka47", 'hello@com.org')
    assert jim.login == "aka47"
    assert jim._UserMail__email == "hello@com.org"
    assert isinstance(jim, UserMail)
    assert isinstance(type(jim).email, property), 'Вы не создали property email'

    jim.email = [1, 2, 3]  # печатает ErrorMail:[1, 2, 3]
    jim.email = 'hello@@re.ee'  # печатает ErrorMail:hello@@re.ee
    jim.email = 'hello@re.w3'
    assert jim.email == 'hello@re.w3'

    k = UserMail('belosnezhka', 'prince@wait.you')
    assert k.email == 'prince@wait.you'
    assert k.login == 'belosnezhka'
    assert isinstance(k, UserMail)

    k.email = {1, 2, 3}  # печатает ErrorMail:{1, 2, 3}
    k.email = 'prince@still@.wait'  # печатает ErrorMail:prince@still@.wait
    k.email = 'prince@stillwait'  # печатает ErrorMail:prince@stillwait
    k.email = 'prince@still.wait'
    assert k.get_email() == 'prince@still.wait'
    k.email = 'pri.nce@stillwait'  # печатает ErrorMail:pri.nce@stillwait
    assert k.email == 'prince@still.wait'


if __name__ == '__main__':
    main()