# Student ID: 012498637
# Student Name: Zakaria Benmoulay
# Course: C950 - Data Structures and Algorithms II


class Package:

    def __init__(
        self,
        package_id,
        address,
        city,
        state,
        zip_code,
        deadline,
        weight,
        notes="",
    ):
        # Let's store the core delivery data from the Package File
        self.package_id = int(package_id)
        self.address    = address.strip()
        self.city       = city.strip()
        self.state      = state.strip()
        self.zip_code   = str(zip_code).strip()
        self.deadline   = deadline.strip()
        self.weight     = weight
        self.notes      = notes.strip()

        # Let's initialize the status tracking fields for the simulation
        self.status         = "At Hub"
        self.departure_time = None
        self.delivery_time  = None
        self.truck_id       = None


    # STATUS UPDATES

    def mark_en_route(self, departure_time, truck_id):

        # Called when a truck departs the hub carrying this package.
        self.status         = "En Route"
        self.departure_time = departure_time
        self.truck_id       = truck_id

    def mark_delivered(self, delivery_time):

        # Called when the truck arrives at this package's delivery address.

        self.status        = "Delivered"
        self.delivery_time = delivery_time

    # TIME-BASED STATUS QUERY

    def status_at(self, query_time):

        # Return the status this package had at a specific point in time.

        # Package is still at the hub if no truck has departed with it yet,
        # or if the query time is before the truck's departure.
        if self.departure_time is None or query_time < self.departure_time:
            return "At Hub"

        # Package is en route if the truck has left but delivery hasn't happened yet
        if self.delivery_time is None or query_time < self.delivery_time:
            return "En Route"

        # Otherwise the package was already delivered by query_time
        return "Delivered"

    # DISPLAY

    def __repr__(self):
        return (
            f"Package({self.package_id:>2}, "
            f"{self.address:<38} "
            f"Deadline: {self.deadline:<8} "
            f"Wt: {self.weight:<4} "
            f"Status: {self.status})"
        )
