package info.bukova.isspst.data;

import info.bukova.isspst.StringUtils;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Embeddable;

import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;

@Embeddable
@Indexed
public class AddressEmb
{

	private int id;
	@Field(index = Index.YES, analyze = Analyze.YES)
	private String company;
	private String department;
	private String contactName;
	private String street;
	private String houseNumber;
	private String zipCode;
	private String city;
	private String state;
	private long ic;
	private String dic;
	private String phone;
	private String email;
	private String web;
	private String description;

	public AddressEmb()
	{
		super();
	}

	public AddressEmb(Address address)
	{
		if (address == null)
		{
			return;
		}

		this.id = address.getId();
		this.company = address.getCompany();
		this.department = address.getDepartment();
		this.contactName = address.getContactName();
		this.street = address.getStreet();
		this.houseNumber = address.getHouseNumber();
		this.zipCode = address.getZipCode();
		this.city = address.getCity();
		this.state = address.getState();
		this.ic = address.getIc();
		this.dic = address.getDic();
		this.phone = address.getPhone();
		this.email = address.getEmail();
		this.web = address.getWeb();
		this.description = address.getDescription();
	}

	public Address getAddress()
	{
		Address address = new Address();

		address.setId(this.id);
		address.setCompany(this.company);
		address.setDepartment(this.department);
		address.setContactName(this.contactName);
		address.setStreet(this.street);
		address.setHouseNumber(this.houseNumber);
		address.setZipCode(this.zipCode);
		address.setCity(this.city);
		address.setState(this.state);
		address.setIc(this.ic);
		address.setDic(this.dic);
		address.setPhone(this.phone);
		address.setEmail(this.email);
		address.setWeb(this.web);
		address.setDescription(this.description);

		return address;
	}

	public int getId()
	{
		return id;
	}

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

	public String getCompany()
	{
		return company;
	}

	public void setCompany(String company)
	{
		this.company = company;
	}

	public String getDepartment()
	{
		return department;
	}

	public void setDepartment(String department)
	{
		this.department = department;
	}

	public String getContactName()
	{
		return contactName;
	}

	public void setContactName(String contactName)
	{
		this.contactName = contactName;
	}

	public String getStreet()
	{
		return street;
	}

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

	public String getHouseNumber()
	{
		return houseNumber;
	}

	public void setHouseNumber(String houseNumber)
	{
		this.houseNumber = houseNumber;
	}

	public String getZipCode()
	{
		return zipCode;
	}

	public void setZipCode(String zipCode)
	{
		this.zipCode = zipCode;
	}

	public String getCity()
	{
		return city;
	}

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

	public String getState()
	{
		return state;
	}

	public void setState(String state)
	{
		this.state = state;
	}

	public long getIc()
	{
		return ic;
	}

	public void setIc(long ic)
	{
		this.ic = ic;
	}

	public String getDic()
	{
		return dic;
	}

	public void setDic(String dic)
	{
		this.dic = dic;
	}

	public String getPhone()
	{
		return phone;
	}

	public void setPhone(String phone)
	{
		this.phone = phone;
	}

	public String getEmail()
	{
		return email;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}

	public String getWeb()
	{
		return web;
	}

	public void setWeb(String web)
	{
		this.web = web;
	}

	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public String toString()
	{
		String str, street;

		List<String> listStreet = new ArrayList<String>();

		if (this.street != null)
		{
			listStreet.add(this.street);
		}

		if (this.houseNumber != null)
		{
			listStreet.add(this.houseNumber);
		}

		street = StringUtils.join(listStreet, " ");

		List<String> list = new ArrayList<String>();

		if (this.company != null)
		{
			list.add(this.company);
		}

		if (street != null)
		{
			list.add(street);
		}

		if (this.city != null)
		{
			list.add(this.city);
		}

		list.add(Long.toString(this.ic));
		str = StringUtils.join(list, ", ");

		return str;
	}

	public static boolean isEqualByAddressEmbForFilter(AddressEmb value, AddressEmb search)
	{
		if ((search == null) || search.toString().isEmpty())
		{
			return true;
		}
		else if (value != null)
		{
			String valueS = value.toString();
			String searchS = search.toString();
			return StringUtils.isEqualForFilter(valueS, searchS);
		}

		return false;
	}
}
