<?php

namespace App\ClientCollection\Corporate\Document;

/**
 * This is the template class for attachment documents associated to corporate collection.
 * @author Gabriel Grosu
 */
abstract class GeneralAbstract
{

	/**
	 * The analyzer class that populates the content.
	 * @var \App\ClientCollection\Corporate\Analyzer
	 */
	protected $analyzer = null;

	/**
	 * Document language code - 'en' as default language
	 * @var string
	 */
	protected $documentLanguageCode = 'en';

	/**
	 * The email attachment file name.
	 * @var string
	 */
	protected $attachmentFileName;

	/**
	 * The full file path (+name) of the temporary file where the attachment is stored on disk, to be sent to the email attachment.
	 * @var string
	 */
	protected $tempFileFullPath = '';

	/**
	 *
	 * @param \App\ClientCollection\Corporate\Analyzer $analyzerObj
	 */
	public function __construct(\App\ClientCollection\Corporate\Analyzer $analyzerObj)
	{
		$this->analyzer = $analyzerObj;
	}

	/**
	 * Sets the doc language.
	 * @param string $documentLanguageCode
	 */
	public function setDocumentLanguageCode($documentLanguageCode):void
	{
		$this->documentLanguageCode = $documentLanguageCode;
	}

	/**
	 * Prepares the temporary file name and populates the content of the report
	 * @throws \Exception
	 */
	public function generateReportContent()
	{
		if (!$this->attachmentFileName) {
			throw new \Exception('Attachment file name (attachmentFileName attribute) not set for '.get_called_class());
		}

		$CFG = \Engine\Loader_Cfg::getInstance()->getGlobal();
		$this->tempFileFullPath = APP_REAL_PATH.$CFG['paths']['temporary']."CorporateCollection_".$this->analyzer->getIdCorporate().".temp";

		$this->populateReport();

	}

	/**
	 * Populates the actual report content.
	 */
	abstract protected function populateReport() :void;

	/**
	 * Returns the temporary file full path+name.
	 * @return string
	 */
	public function getTempFileFullPath()
	{
		if (!$this->tempFileFullPath) {
			throw new \Exception('The temporary full file path is not set - have you called the generateReportContent() method?');
		}
		return $this->tempFileFullPath;
	}


	/**
	 * Returns the attachment file name (as it appears in the
	 * @return String
	 */
	public function getAttachmentFileName()
	{
		return $this->attachmentFileName;
	}


}


