from data import Data

class List:
    def __init__(self,path):
        self.data = Data(path)
        self.mlist = self.data.cache

    def clean(self,item):
        temp = item.strip()
        temp = item.lower()
        return temp
        

    def add_new_item(self,item):
        item = self.clean(item)
        if item in self.mlist:
            raise ValueError("Item '{item}' already in the list".format(item=item))
        self.mlist[item] = ''

    def delete_item(self,item):
        item = self.clean(item)
        if item not in self.mlist:
            raise ValueError("Item '{item}' not in the list".format(item=item))
        self.mlist.pop(item)

    def check_item(self,item):
        item = self.clean(item)
        if item not in self.mlist:
            raise ValueError("Item '{item}' not in the list".format(item=item))
        self.mlist[item] = 'x'

    def print_items(self):
        print("**********")
        print("Item: Status")
        for item,status in self.mlist.items():
            print(item+": "+status)
        print("**********")

if __name__ == "__main__":
    obj = List("data/Movies")
    obj.print_items()
    obj.add_new_item("Children of Men")
    obj.print_items()
    obj.check_item("Children of Men")
    obj.print_items()
    obj.delete_item("Children of Men")
    obj.print_items()
    
