<?php
namespace App\Lidia\DownloadVersion;

class Response extends \App\Lidia\ResponseAbstract
{
	/**
	 * Stores the file part
	 * @var String
	 */
	protected $filePart = NULL;

	/**
	 * Set file part received from LIDIA
	 * @param String $filePart
	 */
	public function setFilePart($filePart)
	{
		$this->filePart = $filePart;
	}

	/**
	 * Returns
	 * @return String
	 */
	public function getFilePart()
	{
		return $this->filePart;
	}

	/**
	 * Returns the file part decoded
	 * @return string
	 */
	public function getFilePartDecoded()
	{
		return base64_decode($this->filePart);
	}

	/**
	 * (non-PHPdoc)
	 * @see \App\Lidia\ResponseAbstract::doCheck()
	 */
	protected function doCheck(\App\MessagesCollector $msgs)
	{
		if ($this->status == 'ok' and !$this->filePart) {
			$msgs->addError(sprintf("The status is `%s`, but file part is not valid.", $this->status));
		}

		if ($this->status == 'ok' and $this->filePart and !$this->getFilePartDecoded()) {
			$msgs->addError("The file part is not encoded correctly");
		}
	}
}
