<?php

namespace App\Services\AssetHistoryDescriptions;

use Facades\App\Services\AssetHistory as AssetHistoryService;

class HistoryForCommon implements HistoryDescription
{

	/**
	 * Get the description for a common status change history.
	 *
	 * @param string $status
	 * @param array $data
	 * @param \App\Models\Asset $asset
	 * @param string|null $comments
	 *
	 * @return string
	 */
	function description($status, $data, $asset, $comments = null)
	{
		$commentstext = ($comments != null) ? " with comments {$comments} " : "";

		$oldLocationOrUsername = AssetHistoryService::getOldLocationOrUsername($asset);
		$oldLocationOrUser = ($oldLocationOrUsername != null) ? (' from ' . $oldLocationOrUsername) : " ";

		$toName = AssetHistoryService::getToLocationOrUsername($data);

		return __('history.Description', [
			'assetname'       => $asset->serial_no,
			'assetid'         => $asset->id,
			'oldasset_status' => optional($asset->assetStatus)->name,
			'newstatus'       => $status,
			'oldusername'     =>  $oldLocationOrUser,
			'roomname'        => $toName,
			'commenttext'     => $commentstext

		]);
	}
}
