import pickle
from cotxe import Cotxe
from colleccio import Colleccio

# Crear objectes Cotxe
c1 = Cotxe('Seat', 'Ibiza', 2018, 'vermell')
c2 = Cotxe('Toyota', 'Corolla', 2020, 'blanc')
c3 = Cotxe('Ford', 'Focus', 2015, 'gris')

# Crear la col·lecció i afegir cotxes
col = Colleccio()
col.afegir(c1)
col.afegir(c2)
col.afegir(c3)

# Escriure la col·lecció al fitxer binari
with open('cotxes.pckl', 'wb') as f:
    pickle.dump(col, f)

print(f"Col·lecció de {len(col)} cotxes guardada a cotxes.pckl")

# Llegir la col·lecció del fitxer binari
with open('cotxes.pckl', 'rb') as f:
    col2 = pickle.load(f)

print("\nCotxes llegits del fitxer:")
col2.mostrar()
