package de.hsadmin.mods.cust;

import static javax.persistence.FetchType.EAGER;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser;

@Entity(name = "BankAccounts")
@Table(name = "bank_account")
public class BankAccount extends AbstractEntity implements Serializable {
	
	private static final long serialVersionUID = 2965368183976686458L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "bank_account_id", columnDefinition = "integer")
	private long id;

	@JoinColumn(name = "bp_id", columnDefinition = "integer")
	@OneToOne(fetch = EAGER)
	private Customer customer;

	@Column(name = "autodebit_ga", columnDefinition = "boolean", nullable = true)
	private Boolean autoDebitGA;

	@Column(name = "autodebit_ar", columnDefinition = "boolean", nullable = true)
	private Boolean autoDebitAR;

	@Column(name = "autodebit_op", columnDefinition = "boolean", nullable = true)
	private Boolean autoDebitOP;

	@Column(name = "bank_customer", columnDefinition = "character varying(50)", nullable = true)
	private String bankCustomer;

	@Column(name = "bank_account", columnDefinition = "character varying(10)", nullable = true)
	private String bankAccount;

	@Column(name = "bank_code", columnDefinition = "character varying(8)", nullable = true)
	private String bankCode;

	@Column(name = "bank_name", columnDefinition = "character varying(50)", nullable = true)
	private String bankName;

	public static String createQueryFromStringKey(String humanKey) {
		return "customer.name = " + humanKey;
	}

	@Override
	public String createStringKey() {
		return getCustomer().getName();
	}

	@Override
	public long id() {
		return id;
	}

	public long getId() {
		return id;
	}

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

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Boolean isAutoDebitGA() {
		return autoDebitGA;
	}

	public Boolean getAutoDebitGA() {
		return autoDebitGA;
	}

	public void setAutoDebitGA(Boolean autoDebitGA) {
		this.autoDebitGA = autoDebitGA;
	}

	public Boolean isAutoDebitAR() {
		return autoDebitAR;
	}

	public Boolean getAutoDebitAR() {
		return autoDebitAR;
	}

	public void setAutoDebitAR(Boolean autoDebitAR) {
		this.autoDebitAR = autoDebitAR;
	}

	public Boolean isAutoDebitOP() {
		return autoDebitOP;
	}

	public Boolean getAutoDebitOP() {
		return autoDebitOP;
	}

	public void setAutoDebitOP(Boolean autoDebitOP) {
		this.autoDebitOP = autoDebitOP;
	}

	public String getBankCustomer() {
		return bankCustomer;
	}

	public void setBankCustomer(String bankCustomer) {
		this.bankCustomer = bankCustomer;
	}

	public String getBankAccount() {
		return bankAccount;
	}

	public void setBankAccount(String bankAccount) {
		this.bankAccount = bankAccount;
	}

	public String getBankCode() {
		return bankCode;
	}

	public void setBankCode(String bankCode) {
		this.bankCode = bankCode;
	}

	public String getBankName() {
		return bankName;
	}

	public void setBankName(String bankName) {
		this.bankName = bankName;
	}

	@Override
	public boolean isNew() {
		return id == 0;
	}

	@Override
	public UnixUser owningUser(EntityManager em) {
		return customer.owningUser(em);
	}
}
