/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Arbalo AG
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.opentdc.addressbooks;

import java.util.Comparator;
import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class AddressModel {
	private String id;			// sortable
	private AddressType addressType;  		// mandatory (PHONE | EMAIL | WEB | MESSAGING | POSTAL )
	private AttributeType attributeType;    // mandatory (HOME | WORK | OTHER)
	private MessageType msgType;   				// TWITTER | FACEBOOK | FLICKR | SKYPE | LINKEDIN | OTHER
	private String value;   // mandatory (if addressType!=POSTAL), e.g. +41 79 1234567, hans.muster@gmail.com
	private String street; // maybe multiple lines
	private String postalCode; 
	private String city;
	private String country;
	private Date createdAt;
	private String createdBy;
	private Date modifiedAt;
	private String modifiedBy;

	public AddressModel() {
		
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public AddressType getAddressType() {
		return addressType;
	}

	public void setAddressType(AddressType addressType) {
		this.addressType = addressType;
	}

	public AttributeType getAttributeType() {
		return attributeType;
	}

	public void setAttributeType(AttributeType type) {
		this.attributeType = type;
	}

	public MessageType getMsgType() {
		return msgType;
	}

	public void setMsgType(MessageType msgType) {
		this.msgType = msgType;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	public Date getModifiedAt() {
		return modifiedAt;
	}

	public void setModifiedAt(Date modifiedAt) {
		this.modifiedAt = modifiedAt;
	}

	public String getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(String modifiedBy) {
		this.modifiedBy = modifiedBy;
	}
	
	/******************************* Comparator *****************************/
	public static Comparator<AddressModel> AddressComparator = new Comparator<AddressModel>() {

		public int compare(AddressModel obj1, AddressModel obj2) {
			if (obj1.getId() == null) {
				return -1;
			}
			if (obj2.getId() == null) {
				return 1;
			}

			String _attr1 = obj1.getId();
			String _attr2 = obj2.getId();

			// ascending order
			return _attr1.compareTo(_attr2);

			// descending order
			// return _attr2.compareTo(_attr1);
		}
	};
}

@@ -1906,16 +1906,26 @@
 le lines
+, optional
 %0A%09privat
@@ -1945,16 +1945,28 @@
 alCode; 
+ // optional
 %0A%09privat
@@ -1979,16 +1979,29 @@
 ng city;
+%09%09// optional
 %0A%09privat
@@ -2002,30 +2002,29 @@
 private 
-String
+short
  country
 ;%0A%09priva
@@ -2015,17 +2015,50 @@
  country
-;
+Code;%09// ISO Code, default: 0 = NA
 %0A%09privat
@@ -3213,30 +3213,29 @@
 %09%7D%0A%0A%09public 
-String
+short
  getCountry(
@@ -3233,16 +3233,20 @@
 tCountry
+Code
 () %7B%0A%09%09r
@@ -3250,32 +3250,36 @@
 %09%09return country
+Code
 ;%0A%09%7D%0A%0A%09public vo
@@ -3295,23 +3295,26 @@
 ntry
-(String country
+Code(short isoCode
 ) %7B%0A
@@ -3331,18 +3331,22 @@
 ntry
- = country
+Code = isoCode
 ;%0A%09%7D

change stringified country to ISO-countryCode