package ch.openech.client.ewk.event;

import java.util.Collections;
import java.util.List;

import ch.openech.client.e07.MunicipalityField;
import ch.openech.client.e10.AddressField;
import ch.openech.client.preferences.OpenEchPreferences;
import ch.openech.dm.common.DwellingAddress;
import ch.openech.dm.common.MunicipalityIdentification;
import ch.openech.dm.person.Person;
import ch.openech.mj.db.model.Constants;
import ch.openech.mj.edit.form.Form;
import ch.openech.xml.write.EchSchema;
import ch.openech.xml.write.WriterEch0020;

public class MoveEvent extends PersonEventEditor<MoveEvent.MoveEventData> {
	
	public MoveEvent(EchSchema echSchema, OpenEchPreferences preferences) {
		super(echSchema, preferences);
	}

	public static class MoveEventData extends DwellingAddress {
		public MunicipalityIdentification reportingMunicipality;
	}

	private static final MoveEventData MED = Constants.of(MoveEventData.class);
	
	@Override
	protected void fillForm(Form<MoveEventData> formPanel) {
		formPanel.line(MED.EGID);
		formPanel.line(MED.EWID);
		formPanel.line(MED.householdID);
		formPanel.area(new AddressField(MED.mailAddress, true, false, false));
		formPanel.line(MED.typeOfHousehold);
		formPanel.area(new MunicipalityField(MED.reportingMunicipality, true));
	}

	@Override
	public MoveEventData load() {
		MoveEventData data = new MoveEventData();
		if (getPerson().dwellingAddress != null) {
			DwellingAddress dwellingAddress = getPerson().dwellingAddress;
			data.EGID = dwellingAddress.EGID;
			data.EWID = dwellingAddress.EWID;
			data.householdID = dwellingAddress.householdID;
			data.mailAddress = dwellingAddress.mailAddress;
			data.typeOfHousehold = dwellingAddress.typeOfHousehold;
			data.reportingMunicipality = getPerson().residence.reportingMunicipality;
		}
		data.movingDate = null;
		return data;
	}

	@Override
	protected List<String> getXml(Person person, MoveEventData address, WriterEch0020 writerEch0020) throws Exception {
		return Collections.singletonList(writerEch0020.move(person.personIdentification, address.reportingMunicipality, address));
	}
	
//	@Override
//	public void validate(List<ValidationMessage> resultList) {
//		super.validate(resultList);
//		getAddress().validate(resultList);
//	}


}

@@ -754,23 +754,70 @@
 entData 
-extends
+%7B%0A%09%09public final DwellingAddress dwellingAddress = new
  Dwellin
@@ -824,18 +824,19 @@
 gAddress
- %7B
+();
 %0A%09%09publi
@@ -1060,16 +1060,32 @@
 ine(MED.
+dwellingAddress.
 EGID);%0A%09
@@ -1104,16 +1104,32 @@
 ine(MED.
+dwellingAddress.
 EWID);%0A%09
@@ -1148,16 +1148,32 @@
 ine(MED.
+dwellingAddress.
 househol
@@ -1216,16 +1216,32 @@
 eld(MED.
+dwellingAddress.
 mailAddr
@@ -1288,16 +1288,32 @@
 ine(MED.
+dwellingAddress.
 typeOfHo
@@ -1605,16 +1605,32 @@
 %09%09%09data.
+dwellingAddress.
 EGID = d
@@ -1658,16 +1658,32 @@
 %09%09%09data.
+dwellingAddress.
 EWID = d
@@ -1711,16 +1711,32 @@
 %09%09%09data.
+dwellingAddress.
 househol
@@ -1778,16 +1778,32 @@
 %09%09%09data.
+dwellingAddress.
 mailAddr
@@ -1845,16 +1845,32 @@
 %09%09%09data.
+dwellingAddress.
 typeOfHo
@@ -1995,16 +1995,83 @@
 ;%0A%09%09
-%7D%0A%09%09data
+%09%0A%09%09%09data.dwellingAddress.echSchema = echSchema;%0A%09%09%7D%0A%09%09data.dwellingAddress
 .mov
@@ -2176,23 +2176,19 @@
 entData 
-address
+med
 , Writer
@@ -2312,23 +2312,19 @@
 cation, 
-address
+med
 .reporti
@@ -2339,17 +2339,29 @@
 pality, 
-a
+med.dwellingA
 ddress))

fix (used inheritence)