/***
 * Excerpted from "Domain-Driven Design Using Naked Objects",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/dhnako for more book information.
***/
package com.pragprog.dhnako.carserv.wicket.ui;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.PropertyModel;

import com.pragprog.dhnako.carserv.dom.customer.Customer;
import com.pragprog.dhnako.carserv.dom.service.ServiceableVehicle;

public class CustomerVehiclesPanel extends NakedObjectsPanel {
	
	private static final long serialVersionUID = 1L;

	public CustomerVehiclesPanel(final String id, final Customer customer) {
		super(id);
		add(new Label("customerName", customer.title()));
		add(new ListView("vehicleList", new PropertyModel(customer, "vehicles")) {
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem item) {
				ServiceableVehicle vehicle = (ServiceableVehicle) item.getModelObject();
				String regNum = vehicle.getRegistrationNumber().getValue();
				String model = vehicle.getModel().title();
				item.add(new Label("regnum", regNum));
				item.add(new Label("model", model));
				item.add(new Label("serviceCount", ""+vehicle.getServices().size()));
			}
		});
	}
}
