'''
시작 시각 : 새벽 5시 즈음
종료 시각 : 오후 5시 12분 (오전에 서울에서 미팅이 있어서 길게 잡혔습니다. 순 코딩시간은 2시간 정도 걸렸습니다.)
'''


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


class Shop:
    def __init__(self):
        self.ingredient = {}
        self.poor = {}
        self.product = {}

    def buy_ingredient(self, buy_dict):

        for key1 in self.ingredient:
            for key2 in buy_dict:
                if (key1 == key2):
                    c = self.ingredient[key1] + buy_dict[key2]
                    self.ingredient[key1] = c

        self.ingredient = {**buy_dict, **self.ingredient}

    def current_ingredient(self):
        print("현재 보유한 재료는", end=' ')
        for key in self.ingredient:
            print(f"{key} ({self.ingredient[key]}개)", end=',')
        print("입니다.")

    def make_cake(self, cake):
        k = 0
        self.poor = {}
        pop = []

        for key1 in cake.ingredient:
            for key2 in self.ingredient:
                if (key1 == key2):
                    t = self.ingredient[key2] - cake.ingredient[key1]
                    self.ingredient[key2] = t
                    if (t >= 0):
                        k += 1

            if (not (key1 in self.ingredient)):
                self.poor[key1] = cake.ingredient[key1]

        for key3 in self.ingredient:
            if (self.ingredient[key3] == 0):
                pop.append(key3)
        if (pop):
            del self.ingredient[pop[0]]

        if (k == 3 or k == 4):
            print(f"{cake.name} 1개 완성!")
            if (cake.name in self.product):
                self.product[cake.name] += 1
            else:
                self.product[cake.name] = 1
        else:
            for a in cake.ingredient:
                if (a in self.ingredient):
                    self.ingredient[a] += cake.ingredient[a]
            for key in self.poor:
                print(f"{key}재료가{self.poor[key]}개", end=',')
            print("부족합니다.")


class Pos:
    def __init__(self, Shop):
        self.product = Shop.product
        self.money = 0

    def current_cakes(self):
        print("현재 재고는")
        for i in self.product:
            print(f"{i}: {self.product[i]}")

    def sell_cake(self, cakename):
        cakes = [cheesecake, chococake, carrotcake, creamcake, swpotatocake]
        for i in cakes:
            if (i.name == cakename):
                k = i
        if cakename in self.product:
            self.product[cakename] -= 1
            print(f"{cakename} 판매 완료. 현재 남은 {cakename}의 개수는 {self.product[cakename]}개 입니다.")
            self.money += k.price
            if self.product[cakename] == 0:
                del self.product[cakename]
        else:
            print(f"{cakename} 재고가 없습니다.")

    def print_current_money(self):
        print(f"현재 판매 금액은 총 {self.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_shpos = Pos(cake_shop)
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()

