package  ch.openech.model.person;

import org.minimalj.model.Keys;

import ch.openech.model.code.NationalityStatus;
import ch.openech.model.common.CountryIdentification;

public class Nationality  {

	public static final Nationality $ = Keys.of(Nationality.class);
	
	public NationalityStatus nationalityStatus;
	public CountryIdentification nationalityCountry;
	
	public Nationality() {
		this(CountryIdentification.createSwiss());
	}
	
	public Nationality(CountryIdentification nationalityCountry) {
		this.nationalityCountry = nationalityCountry;
		this.nationalityStatus = NationalityStatus.with;
	}
	
	private Nationality(NationalityStatus nationalityStatus) {
		this.nationalityStatus = nationalityStatus;
	}
	
	public static final Nationality newUnknown() {
		return new Nationality(NationalityStatus.unknown);
	}

	public static final Nationality newWithout() {
		return new Nationality(NationalityStatus.without);
	}

	public boolean isSwiss() {
		return nationalityStatus == NationalityStatus.with && nationalityCountry != null && nationalityCountry.isSwiss();
	}

	public void copyTo(Nationality copy) {
		copy.nationalityStatus = nationalityStatus;
		copy.nationalityCountry = nationalityCountry;
	}

	@Override
	public int hashCode() {
		if (nationalityStatus == NationalityStatus.with) {
			return nationalityCountry.hashCode();
		} else if (nationalityStatus == null) {
			return 0;
		} else {
			return nationalityStatus.hashCode();
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null || !(obj instanceof Nationality)) {
			return false;
		}
		Nationality other = (Nationality) obj;
		if (nationalityStatus != other.nationalityStatus) {
			return false;
		}
		if (nationalityStatus == NationalityStatus.with) {
			return other.nationalityCountry.equals(nationalityCountry);
		} else {
			return true;
		}
	}

	@Override
	public String toString() {
		if (nationalityStatus == NationalityStatus.without) {
			return "Staatenlos";
		} else if (nationalityStatus == NationalityStatus.unknown) {
			return "Staatsangehörigkeit unbekannt";
		} else if (nationalityStatus == NationalityStatus.with) {
			return nationalityCountry.toString();
		} else {
			return nationalityStatus + " / " + nationalityCountry.toString();
		}
	}

	public void clear() {
		nationalityStatus = NationalityStatus.unknown;
		nationalityCountry = null;
	}
	
}

@@ -39,31 +39,94 @@
 ort 
-org.minimalj.model.Keys
+java.util.Locale;%0A%0Aimport org.minimalj.model.Keys;%0Aimport org.minimalj.model.Rendering
 ;%0A%0Ai
@@ -252,16 +252,36 @@
 onality 
+implements Rendering
  %7B%0A%0A%09pub
@@ -1914,32 +1914,33 @@
 rn true;%0A%09%09%7D%0A%09%7D%0A
+%09
 %0A%09@Override%0A%09pub
@@ -1950,25 +1950,59 @@
  String 
-toString(
+render(RenderType renderType, Locale locale
 ) %7B%0A%09%09if
@@ -2268,33 +2268,49 @@
 lityCountry.
-toString(
+render(renderType, locale
 );%0A%09%09%7D else 

implement Rendering for correct display in combo boxes