/*
 * SistemaBancarioControlador.java
 *
 * Created on April 7, 2003, 7:12 PM
 */

package cib412.poo.banco;

/**
 *
 * @author  do008548
 */
public class SistemaBancarioControlador {
    private SistemaBancarioGUI vista;
    private Banco banco;
    private CuentaBancariaControlador controladorCuenta;
    /** Creates a new instance of SistemaBancarioControlador */
    public SistemaBancarioControlador(SistemaBancarioGUI v, Banco b) {
        vista = v;
        controladorCuenta = new CuentaBancariaControlador(
             new CuentaBancariaGUI(v.getVentana()));
        banco = b;
    }
    
    public void controlar() {
        boolean salir = false;
        while (!salir) {
            String seleccion = vista.seleccionarMenu();
            if ( SistemaBancarioGUI.NUEVACUENTA.equals(seleccion)) {
                CuentaBancaria cuenta=controladorCuenta.capturar();
                if (cuenta!=null) {
                 banco.agregarCuenta(cuenta);
                 vista.mensaje("Cuenta agregada, existen "+ 
                    banco.getNumCuentas() +" cuentas");
                } else {
                  vista.mensaje("No se capturo nueva cuenta");   
                }
            } else if (SistemaBancarioGUI.BALANCE.equals(seleccion) ) {
                banco.balance(0.1);
                vista.mensaje("Balance concluido");
            } else if (SistemaBancarioGUI.BUSCAR.equals(seleccion) ) {
                String id = vista.preguntarIdentificadorCuenta();
                CuentaBancaria cuenta= banco.buscar(id);
                if (cuenta!=null) {
                    controladorCuenta.imprimir(cuenta);
                    
                } else {
                    vista.mensaje("No existe la cuenta "+id);
                }
            } else if (SistemaBancarioGUI.SALIR.equals(seleccion)) {
                salir = true;
            }
        }
    }
    
}
