'''
시작 시각 :
종료 시각 :
'''


class Cake:
    def __init__(self,name,price,ingredient):
        self.name=name
        self.price=price
        self.ingredient=ingredient

init_ingredient = {'cheese':0,'chocolate':0,'carrot':0,'sweet potato':0,'egg':0,'butter':0,'walnut':0,'cream':0}
init_cake={}
cakes={}

class Shop:

    def buy_ingredient(self, buy_dict):
        global init_ingredient
        self.ingredient=init_ingredient
        for i in buy_dict.keys():
            self.ingredient[i]=self.ingredient[i]+buy_dict[i]
    def current_ingredient(self):
        print('현재 보유한 재료는', end=' ')
        for i in init_ingredient.keys():
            if self.ingredient.get(i) > 0:
                print('%s(%d)개' %(i, self.ingredient.get(i)), end=', ')
        print('입니다.')
        print('\n')
    

    def make_cake(self, cake):
        empty_ingredient = dict.copy(self.ingredient)
        new_dict={}
        for i in cake.ingredient:
            if i in empty_ingredient:
                if cake.ingredient[i] <= empty_ingredient[i]:
                    empty_ingredient[i]= empty_ingredient[i]- cake.ingredient[i]
                else:
                    new_dict[i]=cake.ingredient[i]
        if len(new_dict)>0:
            ingredient_list = list(new_dict)
            for k in range(len(ingredient_list)):
                if k == len(ingredient_list)-1:
                    print('%s 재료가 %d개 부족합니다.' %(ingredient_list[k], new_dict[ingredient_list[k]]))
                else:
                    print('%s 재료가 %d개, ' %(ingredient_list[k], new_dict[ingredient_list[k]]), end='')
        else:
            global cakes
            for ingredient in cake.ingredient:
                self.ingredient[ingredient] = self.ingredient[ingredient] - cake.ingredient[ingredient]

                if self.ingredient[ingredient] <= 0:
                    self.ingredient.pop(ingredient)
            print('%s 1개 완성!' %cake.name)
            if cake.name not in cakes.keys():
                    cakes[cake.name] = 1 
            else:
                    cakes[cake.name] = cakes[cake.name] + 1
        self.product=cakes
        return self.product
        


money=0

class Pos:
    def __init__(self, cake_shop):
        self.cake_shop=cake_shop
        self.money=money

    def current_cakes(self):
        print('현재 재고는')
        for key, value in cake_shop.product.items():
            print('%s : %d' %(key, value))

    def sell_cake(self, cakename):
        global money
        if cakename in cake_shop.product.keys():
            cake_shop.product[cakename]=cake_shop.product.get(cakename)-1
            if cakename == cheesecake.name:
                money=money+cheesecake.price
                print('Cheese Cake 판매 완료. 현재 남은 Cheese Cake의 개수는 %d개 입니다.' %cake_shop.product[cakename])
            if cakename == chococake.name:
                money=money+chococake.price
                print('Chocolate Cake 판매 완료. 현재 남은 Chocolate Cake의 개수는 %d개 입니다.' %cake_shop.product[cakename])
            if cakename == carrotcake.name:
                money=money+carrotcake.price
                print('Carrot Cake 판매 완료. 현재 남은 Carrot Cake의 개수는 %d개 입니다.' %cake_shop.product[cakename])
            if cakename == creamcake.name:
                money=money+creamcake.price
                print('Fresh Cream Cake 판매 완료. 현재 남은 Fresh Cream Cake의 개수는 %d개 입니다.' %cake_shop.product[cakename])
            if cakename == swpotatocake:
                money=money+swpotatocake.price
                print('Sweet Potato Cake 판매 완료. 현재 남은 Sweet Potato Cake의 개수는 %d개 입니다.' %cake_shop.product[cakename])

            if cake_shop.product[cakename] <= 0:
                    cake_shop.product.pop(cakename)
        else:
            print('%s 재고가 없습니다.' %cakename)

    def print_current_money(self):
        print('현재 판매 금액은 총 %d원 입니다.' %money)


cheesecake = Cake("Cheese Cake", 6900, {'cheese': 2, 'egg': 2, 'butter': 2})
chococake = Cake("Chocolate Cake", 5900, {'chocolate': 2, 'egg': 2, 'butter': 2})
carrotcake = Cake("Carrot Cake", 5500, {'carrot': 2, 'walnut': 2, 'egg': 1, 'butter': 1})
creamcake = Cake("Fresh Cream Cake", 4500, {'cream': 3, 'egg': 1, 'butter': 1})
swpotatocake = Cake("Sweet Potato Cake", 6500, {'sweet potato': 3, 'egg': 2, 'butter': 1})

cake_shop = Shop()
cake_shop.buy_ingredient({'cheese': 5, 'carrot': 3, 'sweet potato': 3, 'egg': 10, 'butter': 10})
cake_shop.current_ingredient()
cake_shop.buy_ingredient({'chocolate': 3, 'walnut': 2, 'egg': 12, 'butter': 12})
cake_shop.current_ingredient()

print("\nMAKE CAKE")
cake_shop.make_cake(creamcake)
print(cake_shop.ingredient)
cake_shop.make_cake(carrotcake)
print(cake_shop.ingredient)
cake_shop.make_cake(carrotcake)
print(cake_shop.ingredient)
cake_shop.make_cake(cheesecake)
print(cake_shop.ingredient)
cake_shop.make_cake(cheesecake)
print(cake_shop.ingredient)
cake_shop.make_cake(chococake)
print(cake_shop.ingredient)
cake_shop.make_cake(swpotatocake)
print(cake_shop.ingredient)
cake_shop.current_ingredient()

pos = Pos(cake_shop)
print()
pos.current_cakes()

print()
pos.sell_cake('Cheese Cake')
pos.current_cakes()

print()
pos.sell_cake('Cheese Cake')
pos.current_cakes()

print()
pos.sell_cake('Chocolate Cake')
pos.current_cakes()

print()
pos.sell_cake('Cheese Cake')

print()
pos.print_current_money()
