package com.rjconsultores.ventaboletos.web.gui.controladores.catalogos;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Textbox;

import com.rjconsultores.ventaboletos.utilerias.PasswordHelper;
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;

@Controller("visualizarSenhaInstalacaoController")
@Scope("prototype")
public class VisualizarSenhaInstalacaoController extends MyGenericForwardComposer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Textbox txtSenha;

	private final Logger log = LogManager.getLogger(VisualizarSenhaInstalacaoController.class);

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		String senhaAlpha = geraNovaSenhaInstalacao();
		txtSenha.setText(senhaAlpha);
		txtSenha.setDisabled(true);
	}

	private String geraNovaSenhaInstalacao() {
		try {
			return new PasswordHelper().getInstance().generateRandomPassword();
		} catch (Exception e) {
			log.error("Erro ao validar senha Instalação ", e);
		}
		return "";
	}

	public void onClick$btnRefresh(Event ev) {
		String senhaAlpha;
		senhaAlpha = geraNovaSenhaInstalacao();
		txtSenha.setText(senhaAlpha);
	}

}
