<?php
namespace SabaiApps\Directories\Component\Map\FakerGenerator;

use SabaiApps\Directories\Component\Faker\Generator\AbstractGenerator;
use SabaiApps\Directories\Component\Field\IField;
use SabaiApps\Directories\Component\Entity\Type\IEntity;

class MapFakerGenerator extends AbstractGenerator {

	protected $_viewport;

	protected function _fakerGeneratorInfo() {
		switch ( $this->_name ) {
			case 'map_map':
				return array(
					'field_types'      => array( $this->_name ),
					'add_probability'  => true,
					'default_settings' => array(
						'max' => 5,
					),
				);
		}
	}

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

	public function fakerGeneratorGenerate( IField $field, array $settings, array &$formStorage, ?IEntity $entity = null ) {
		switch ( $this->_name ) {
			case 'map_map':
				$ret   = array();
				$count = $this->_getMaxNumItems( $field, $settings['max'] );
				$faker = $this->_getFaker();
				for ( $i = 0; $i < $count; ++$i ) {
					$ret[ $i ] = array(
						'lat' => $faker->latitude(),
						'lng' => $faker->longitude(),
					);
				}
				return $ret;
		}
	}
}
