package org.sistema.hibernate.manytomanybidirannotations.models;

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

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;

/**
 * BankAccount class.
 * @author Eugenia Pérez Martínez
 * @email eugenia_perez@cuatrovientos.org
 */
@Entity
public class BankAccount {
    @Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="bankaccount_id")
	private Long id;
	private String number;
	private Float deposit;
	
	@ManyToMany
	private List<Customer> customers = new ArrayList<Customer>();

	/**
	 * default constructor
	 */
	public BankAccount () {	
	}


	/**
	 * @param id
	 * @param number
	 * @param deposit
	 * @param customers
	 */
	public BankAccount(Long id, String number, Float deposit,
			List<Customer> customers) {
		this.id = id;
		this.number = number;
		this.deposit = deposit;
		this.customers = customers;
	}

	/**
	 * adds customer to bankaccount
	 * @param customer
	 */
	public void addCustomer (Customer customer) {
		customers.add(customer);
		customer.addAccount(this);
	}
	

	/**
	 * @return the customers
	 */
	public List<Customer> getCustomers() {
		return customers;
	}


	/**
	 * @param customers the customers to set
	 */
	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}


	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the number
	 */
	public String getNumber() {
		return number;
	}

	/**
	 * @param number the number to set
	 */
	public void setNumber(String number) {
		this.number = number;
	}

	/**
	 * @return the deposit
	 */
	public Float getDeposit() {
		return deposit;
	}

	/**
	 * @param deposit the deposit to set
	 */
	public void setDeposit(Float deposit) {
		this.deposit = deposit;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "BankAccount [id=" + id + ", number=" + number + ", deposit="
				+ deposit + ", customers=" + customers + "]";
	}


	
}
