#include "stdafx.h"
#include "AzMessageFactory.h"
#include "AzDefines.h"
#include "AzUtils.h"
#include "resource.h"

CAzMessageFactory::CAzMessageFactory(void)
{
}

CAzMessageFactory::~CAzMessageFactory(void)
{
}

BOOL CAzMessageFactory::Initialize( azstring& strJobName, azstring& strJobGuid )
{
    m_strJobName = strJobName;
    m_strJobGuid = strJobGuid;
    return TRUE;
}

CAzMessagePtr CAzMessageFactory::CreateEmptyMessage()
{
    CAzMessagePtr pAzMessage(new CAzMessage(m_strJobName, m_strJobGuid));
    if( pAzMessage.get() != NULL ) {
        return pAzMessage;
    }
    else {
        return CAzMessagePtr(0);
    }
}

CAzMessagePtr CAzMessageFactory::CreateJobStartMessage()
{
    CAzMessagePtr pAzMessage = CreateEmptyMessage();
    if( pAzMessage.get() != NULL ) {
        azstring strMessage = CAzUtils::LoadString( IDS_EVENT_JOB_START );
        pAzMessage->SetJobMessage( AZ_STATUS_JOB_RUNNING, strMessage.c_str() );
        return pAzMessage;
    }
    else {
        return CAzMessagePtr(0);
    }
}

CAzMessagePtr CAzMessageFactory::CreateJobEndMessage(DWORD dwJobExitCode)
{
    CAzMessagePtr pAzMessage = CreateEmptyMessage();
    if( pAzMessage.get() != NULL ) {
        azstring strMessage = CAzUtils::LoadString( IDS_EVENT_JOB_END );
        pAzMessage->SetJobMessage( AZ_STATUS_JOB_END, strMessage.c_str(), dwJobExitCode);
        return pAzMessage;
    }
    else {
        return CAzMessagePtr(0);
    }
}

CAzMessagePtr CAzMessageFactory::CreateJobErrorMessage(AZSTATUS dwJobStatus, LPCTSTR pszErrorMessage)
{
	CAzMessagePtr pAzMessage = CreateEmptyMessage();
	if (pAzMessage.get() != NULL) {
		azstring strMessage = CAzUtils::LoadString( IDS_EVENT_JOB_ERROR );
		strMessage += _T(" ");
		strMessage += pszErrorMessage;
		pAzMessage->SetJobMessage(dwJobStatus, strMessage.c_str());
		return pAzMessage;
	}
	else {
		return CAzMessagePtr(0);
	}
}

CAzMessagePtr CAzMessageFactory::CreateHeartbeatMessage()
{
	CAzMessagePtr pAzMessage = CreateEmptyMessage();
	if (pAzMessage.get() != NULL) {
		azstring strMessage = CAzUtils::LoadString(IDS_EVENT_JOB_HEARTBEAT);
		pAzMessage->SetJobMessage(AZ_STATUS_JOB_RUNNING, strMessage.c_str());
		return pAzMessage;
	}
	else {
		return CAzMessagePtr(0);
	}
}

CAzMessagePtr CAzMessageFactory::CreateJobOutputMessage(CAzJobOutput* pJobOutput)
{
    CAzMessagePtr pAzMessage = CreateEmptyMessage();
    if (pAzMessage.get() != NULL) {
        azstring strMessage(_T(">>>"));
        pAzMessage->SetJobMessage(AZ_STATUS_JOB_RUNNING, strMessage.c_str());
        return pAzMessage;
    }
    else {
        return CAzMessagePtr(0);
    }
}

