
import datetime
import time
from collections import namedtuple
Bedroom = namedtuple('Bedroom', 'room_num ')
Reservation = namedtuple('Reservation', 'room_num checkinDate checkoutDate lastName firstName')
def stage4():

    list_of_bedrooms = []
    list_of_reservations = []
    reservation_dict = {}
    bb = open ('stage4.txt', 'r')
    lines = bb.readlines()
    for line in lines:
        
        x = line.split()
        if x[0].upper() == 'PL':
            print(line[3:])
            
        elif x[0].upper() == 'NB':
            list_of_bedrooms.append(x[1])
            ipn list_of_reservations:
                print("sorry, can't add room ", x[1], " again; it's already on the list")
              
        elif x[0].upper() == 'RR':
            for reservation in list_of_reservations:
                if int(x[1]) in Reservation.room_num:
                    reservation_dict.pop(int(x[1]))
                    
                else:
                    print("Sorry, can't cancel reservation; no confirmation number" ,x[1])

        
        
        elif x[0].upper() == 'NR':
            if x[1] in list_of_bedrooms:
                arrive_date = time.strptime(x[2], "%m/%d/%Y")
                depart_date = time.strptime(x[3], "%m/%d/%Y")
                if arrive_date  < depart_date and arrive_date != depart_date:
                    canPrint = True
                else:
                    canPrint = False
                if canPrint:
                    
                        r = Reservation(x[1], x[2], x[3], x[4], x[5])
                        list_of_reservations.append(r)

                        confirmation_num = 1
                        for i  in list_of_reservations:
                            reservation_dict[confirmation_num] = i
                            confirmation_num += 1
                        print("Reserving room", x[1], "for", x[4], x[5], "-- Confirmation #", confirmation_num - 1)
                        print("\t(arriving", x[2], ", departing", x[3], ")")
                      
                        if x[1] in reservation_dict:
                             
                                print("sorry cannot be reserved, it is already booked confiramtion number is ", key)  

                        
                else:
                    print("Sorry, can't reserve room", x[1], "(", x[2], "to", x[3], ");")
                    print("\tcan't leave before you arrive.")
            
            else:
                print("Sorry; can't reserve room", x[1],"; room not in service")

        elif x[0].upper() == 'LR':
            print ('Number of reservations:', len(list_of_reservations))
            print('No. Rm. Arrive      Depart     Guest')
            print('------------------------------------------------')
            confirmation = 0
            for k,v in reservation_dict.items():
                print("{:3d} {:3s} {:10s} {:10s} {:15s}".format(k,v.room_num,v.checkinDate, v.checkoutDate, v.lastName  +" " + v.firstName))

       
stage4()

