import misc_class
import pickle


def coin_test():
    my_coin = misc_class.Coin()

    print('Эта сторона обращена вверх:', my_coin.get_sideup())

    # Подбросить монету
    print('Сибираюсь подбросить монету 10 раз:')
    for _ in range(10):
        my_coin.toss()
        print(my_coin.get_sideup())

def bankaccount_test():
    start_bal = 100.5
    savings = misc_class.BankAccaunt(start_bal)
    print(f'Остаток составляет ${savings.get_balance():,.2f}')
    savings.deposit(50.0)

    # Здесь будет вызван метод __str__
    print(savings)  

    savings.withdraw(75.4)

    # Здесь тоже будет вызван метод __str__, но через str()
    print(str(savings))    


# Создает 4 объектов CellPhone и сохраняет из в списке
def cellphone_test():
    phone_list = []

    for _ in range(5):
        phone = misc_class.CellPhone()
        phone_list.append(phone)

    for item in phone_list:
        print(item.get_manufact())        
        print(item.get_model())
        print(item.get_retail_price())

# Сериализация/десериализация объектов
def cellphone_serial():
    FILE_NAME = 'cellphones.dat'    
    file = open(FILE_NAME, 'wb')

    for _ in range(5):
        phone = misc_class.CellPhone()
        pickle.dump(phone, file)

    file.close()
    print(f'Данные записаны в {FILE_NAME}')

    file = open(FILE_NAME, 'rb')
    end_of_file = False
    while not end_of_file:
        try:
            phone = pickle.load(file)
            print(f'Производитель: {phone.get_manufact()}')
            print(f'Номер моделы: {phone.get_model()}')
            print(f'Розничная цена: {phone.get_retail_price()}')
            print()
        except Exception as e:
            end_of_file = True

    file.close()



def main():
    #
    # coin_test()    

    # Методы __str__
    # bankaccount_test()

    # Создание списка объектов CellPhone
    # cellphone_test()

    # Сериализация объектов 
    # cellphone_serial()

    pass


if __name__ == '__main__':
    main()