# nursery.py: starting script for Class 12
# Class Tray of Class 11 (2.4): trays of different sizes, with read-only properties.


class Tray:
    CAPACITIES = (24, 50, 104)          # class variable: standard tray sizes

    def __init__(self, species, n_plants=0, capacity=50):
        if capacity not in Tray.CAPACITIES:
            raise ValueError(f"capacity must be one of {Tray.CAPACITIES}")
        if n_plants < 0:
            raise ValueError("n_plants cannot be negative")
        if n_plants > capacity:
            raise ValueError(f"the tray only has {capacity} cells")
        self.species = species
        self._capacity = capacity
        self._n_plants = n_plants

    @property
    def capacity(self):                 # read-only
        return self._capacity

    @property
    def n_plants(self):                 # read-only
        return self._n_plants

    @property
    def free_cells(self):               # computed from the other attributes
        return self._capacity - self._n_plants

    def add_plants(self, n):
        if n > self.free_cells:
            raise ValueError(f"the tray only has {self.capacity} cells, and {self.free_cells} are free")
        self._n_plants += n

    def remove_plants(self, n):
        if n > self._n_plants:
            raise ValueError(f"the tray only has {self._n_plants} plants")
        self._n_plants -= n

    def __str__(self):
        return f"{self.n_plants} {self.species} plants ({self.free_cells} free cells)"
