<?php

namespace App\Reports\Sources\DocsList;

class PopulateLoopRecords extends \App\Reports\Sources\PopulateLoopRecordsAbstract
{

	/**
	 * These are the standard columns that we expect are filled in during the loop records. The list
	 * may not contain anyting
	 * @var array
	 */
	protected array $processStandardColumns = [
		'customText01_name', 'customText01_val', 'customText02_name', 'customText02_val', 'customText03_name', 'customText03_val', 'customText04_name', 'customText04_val', 'customText05_name', 'customText05_val',
		'customText06_name', 'customText06_val', 'customText07_name', 'customText07_val', 'customText08_name', 'customText08_val', 'customText09_name', 'customText09_val', 'customText10_name', 'customText10_val',
		'customText11_name', 'customText11_val', 'customText12_name', 'customText12_val', 'customText13_name', 'customText13_val', 'customText14_name', 'customText14_val', 'customText15_name', 'customText15_val',
		'customText16_name', 'customText16_val', 'customText17_name', 'customText17_val', 'customText18_name', 'customText18_val', 'customText19_name', 'customText19_val', 'customText20_name', 'customText20_val',
	];

	/**
	 * {@inheritDoc}
	 * @see \App\Reports\Sources\PopulateLoopRecordsAbstract::updateReportStdColumns()
	 */
	protected function updateReportStdColumns(array $currentRow) :array
	{

		// loads all the standard columns from
		$tableColumns = $this->columnsManager->getStdColumns();

		$updateColumns = [];

		// set the custom fields
		if ($currentRow['doc_fieldsDetails']) {
			$docFldDet = json_decode($currentRow['doc_fieldsDetails'], true);
			for($i=1;$i<=20;$i++) {
				$count=sprintf("%02d", $i);

				// field name
				if ($tableColumns['customText'.$count.'_name'] and $docFldDet['customText'.$count]['name']) {
					$updateColumns['customText'.$count.'_name'] = $docFldDet['customText'.$count]['name'];
				}
				// field value
				if ($tableColumns['customText'.$count.'_val'] and $docFldDet['customText'.$count]['value']) {
					$updateColumns['customText'.$count.'_val'] = $docFldDet['customText'.$count]['value'];
				}
			}
		}



		return $updateColumns;

	}

}