#include "K2CrystalAuthPrompt.h"
#include "K2ICrystalCallback.h"

NS_IMPL_ISUPPORTS1(K2CrystalAuthPrompt, nsIAuthPrompt)

K2CrystalAuthPrompt::K2CrystalAuthPrompt( K2ICrystalCallback & crystal )
{
	this->crystal = &crystal;
}

/* boolean prompt (in wstring dialogTitle, in wstring text, in wstring passwordRealm, in PRUint32 savePassword, in wstring defaultText, out wstring result); */
NS_IMETHODIMP K2CrystalAuthPrompt::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, PRUint32 savePassword, const PRUnichar *defaultText, PRUnichar **result NS_OUTPARAM, PRBool *_retval NS_OUTPARAM)
{
    return NS_OK;
}

/* boolean promptUsernameAndPassword (in wstring dialogTitle, in wstring text, in wstring passwordRealm, in PRUint32 savePassword, inout wstring user, inout wstring pwd); */
NS_IMETHODIMP K2CrystalAuthPrompt::PromptUsernameAndPassword(
	const PRUnichar *dialogTitle, const PRUnichar *text,
	const PRUnichar *passwordRealm, PRUint32 savePassword,
	PRUnichar **user NS_INOUTPARAM, PRUnichar **pwd NS_INOUTPARAM,
	PRBool *_retval NS_OUTPARAM)
{
	crystal->GetUsername(user);
	crystal->GetPassword(pwd);

	*_retval = (*user && *pwd) ? PR_TRUE : PR_FALSE;

    return NS_OK;
}

/* boolean promptPassword (in wstring dialogTitle, in wstring text, in wstring passwordRealm, in PRUint32 savePassword, inout wstring pwd); */
NS_IMETHODIMP K2CrystalAuthPrompt::PromptPassword(
	const PRUnichar *dialogTitle, const PRUnichar *text,
	const PRUnichar *passwordRealm, PRUint32 savePassword,
	PRUnichar **pwd NS_INOUTPARAM, PRBool *_retval NS_OUTPARAM)
{
	crystal->GetPassword(pwd);
	*_retval = *pwd ? PR_TRUE : PR_FALSE;

    return NS_OK;
}
