<?php
namespace SabaiApps\Directories\Component\Faker\Generator;

use SabaiApps\Directories\Component\Field\IField;
use SabaiApps\Directories\Component\Entity\Type\IEntity;

class CompanyNameGenerator extends AbstractGenerator {

	protected function _fakerGeneratorInfo() {
		return array(
			'label'            => __( 'Company Name Generator', 'directories-pro' ),
			'field_types'      => array( 'entity_title', 'string' ),
			'default_settings' => array(
				'max' => 5,
			),
		);
	}

	public function fakerGeneratorSettingsForm( IField $field, array $settings, $mode, array $parents = array() ) {
		switch ( $field->getFieldType() ) {
			case 'field_string':
				return array(
					'max' => $this->_getMaxNumItemsSettingForm( $field, $settings['max'] ),
				);
		}
	}

	public function fakerGeneratorGenerate( IField $field, array $settings, array &$formStorage, ?IEntity $entity = null ) {
		switch ( $field->getFieldType() ) {
			case 'entity_title':
				return $this->_getFaker()->company();
			case 'field_string':
				$ret   = array();
				$count = $this->_getMaxNumItems( $field, $settings['max'] );
				for ( $i = 0; $i < $count; ++$i ) {
					$ret[] = $this->_getFaker()->company();
				}
				return empty( $ret ) ? null : $ret;
		}
	}
}
