package org.sistema.hibernate.manytomanybidirxml;

import org.sistema.hibernate.manytomanybidirxml.dao.CustomerDAO;
import org.sistema.hibernate.manytomanybidirxml.models.BankAccount;
import org.sistema.hibernate.manytomanybidirxml.models.Customer;

/**
 * Main class to try some operations
 * @author Eugenia Pérez
 * @email eugenia_perez@cuatrovientos.org
 */
public class Main {

	public static void main(String[] args) {
		//Al primer cliente se le asignan tres cuentas
		Customer customer1 = new Customer();
		customer1.setName("Customer1");
		customer1.setAddress("c/ Mayor");
		BankAccount bankAccount1 = new BankAccount();
		bankAccount1.setNumber("11111");
		bankAccount1.setDeposit(4453.23f);
		BankAccount bankAccount2 = new BankAccount();
		bankAccount2.setNumber("22222");
		bankAccount2.setDeposit(42.00f);
		BankAccount bankAccount3 = new BankAccount();
		bankAccount3.setNumber("33333");
		bankAccount3.setDeposit(542.760f);
		customer1.addAccount(bankAccount1);
		customer1.addAccount(bankAccount2);
		customer1.addAccount(bankAccount3);

		//Al clientes 2 le asignamos otras tres cuentas
		Customer customer2 = new Customer();
		customer2.setName("Customer2");
		customer2.setAddress("c/ Menor");
		BankAccount bankAccount4 = new BankAccount();
		bankAccount4.setNumber("44444");
		bankAccount4.setDeposit(1342323.45f);
		BankAccount bankAccount5 = new BankAccount();
		bankAccount5.setNumber("55555");
		bankAccount5.setDeposit(-54f);
		BankAccount bankAccount6 = new BankAccount();
		bankAccount6.setNumber("66666");
		bankAccount6.setDeposit(534.87f);
		customer2.addAccount(bankAccount4);
		customer2.addAccount(bankAccount5);
		customer2.addAccount(bankAccount6);
		
		//Se insertan los dos clientes, con sus cuentas en cascada
		CustomerDAO customerDAO = new CustomerDAO();
		customerDAO.insert(customer1);
		customerDAO.insert(customer2);
		
		//Se borra el último cliente
		customerDAO.delete(customer1);	
	}

}
