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

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

class ReviewFakerGenerator extends AbstractGenerator {

	protected function _fakerGeneratorInfo() {
		switch ( $this->_name ) {
			case 'review_title':
				return array(
					'label'            => __( 'Review Title Generator', 'directories-pro' ),
					'field_types'      => array( 'entity_title' ),
					'default_settings' => array(),
				);
			case 'review_rating':
				return array(
					'field_types'      => array( $this->_name ),
					'default_settings' => array(),
				);
		}
	}

	public function fakerGeneratorGenerate( IField $field, array $settings, array &$formStorage, ?IEntity $entity = null ) {
		switch ( $this->_name ) {
			case 'review_title':
				// 1. Descriptive Adjectives (Condition, atmosphere, and quality)
				$adjectives = array(
					'Amazing',
					'Stunning',
					'Modern',
					'Well-maintained',
					'Spacious',
					'Clean',
					'Quiet',
					'Top-notch',
					'Professional',
					'Cozy',
					'Luxurious',
					'Minimalist',
					'High-tech',
					'Eco-friendly',
					'Accessible',
					'Vibrant',
					'Well-equipped',
					'Pristine',
					'Charming',
					'Functional',
					'Stylish',
					'Impressive',
					'Budget-friendly',
					'Overrated',
					'Dated',
					'Busy',
					'Serene',
					'Welcoming',
					'State-of-the-art',
					'Excellent',
					'Authentic',
					'Polite',
					'Organized',
					'Tidy',
					'Industrial',
					'Classic',
					'Breathtaking',
					'Hidden',
					'Trendy',
					'Efficient',
					'Reliable',
					'Premium',
					'Co-working friendly',
				);
				// 2. Nouns/Subjects (Physical elements and services)
				$subjects = array(
					'facility',
					'lobby',
					'amenities',
					'equipment',
					'common area',
					'gym',
					'lounge',
					'meeting room',
					'interior',
					'design',
					'staff',
					'reception',
					'parking',
					'garden',
					'terrace',
					'lighting',
					'Wi-Fi',
					'restroom',
					'atmosphere',
					'experience',
					'value',
					'location',
					'furniture',
					'cleanliness',
					'view',
					'architecture',
					'pool',
					'vibe',
					'workspace',
					'cafe area',
					'setup',
					'service',
					'management',
					'ambiance',
					'desk',
				);
				// 3. Contextual Suffixes (Target audience and purpose)
				$suffixes = array(
					'for remote work',
					'for a quick visit',
					'in the city center',
					"I've seen lately",
					'for the price',
					'ever!',
					'highly recommended',
					'worth every penny',
					'than the photos show',
					'for families',
					'for business trips',
					'to relax',
					'close to everything',
					'you can find around here',
					'but needs minor work',
					'for solo users',
					'for networking',
					'on a weekend',
					'for long stays',
					'during peak hours',
					'for focused work',
				);
				// 4. Introductory Phrases / Verbs
				$verbs = array(
					'Loved the',
					'Great choice for',
					'Perfect for',
					'Best part was',
					'Highly impressed by',
					'Really liked the',
					'Everything was',
					'Nothing beats the',
					'Unexpectedly good',
					'Disappointed with',
					'Enjoyed the',
					'Fantastic experience with',
					'A bit let down by',
				);
				// Define structural patterns to ensure natural English flow
				$patterns = array(
					// Pattern: [Adjective] [Noun] -> "Modern gym"
					fn() => $adjectives[ array_rand( $adjectives ) ] . ' ' . $subjects[ array_rand( $subjects ) ],
					// Pattern: [Noun] [Suffix] -> "Equipment for remote work"
					fn() => ucfirst( $subjects[ array_rand( $subjects ) ] ) . ' ' . $suffixes[ array_rand( $suffixes ) ],
					// Pattern: [Verb] [Adjective] [Noun] -> "Loved the spacious lobby"
					fn() => $verbs[ array_rand( $verbs ) ] . ' ' . strtolower( $adjectives[ array_rand( $adjectives ) ] ) . ' ' . $subjects[ array_rand( $subjects ) ],
					// Pattern: [Adjective] [Noun] [Suffix] -> "Clean facility for families"
					fn() => $adjectives[ array_rand( $adjectives ) ] . ' ' . $subjects[ array_rand( $subjects ) ] . ' ' . $suffixes[ array_rand( $suffixes ) ],
					// Pattern: Short exclamation -> "Stunning atmosphere!"
					fn() => $adjectives[ array_rand( $adjectives ) ] . ' ' . $subjects[ array_rand( $subjects ) ] . '!',
					// Pattern: Verb phrase -> "Best part was the lighting"
					fn() => $verbs[ array_rand( $verbs ) ] . ' the ' . $subjects[ array_rand( $subjects ) ],
				);
				return $patterns[ array_rand( $patterns ) ]();
			case 'review_rating':
				$ratings = array();
				foreach ( array_keys( $this->_application->Review_Criteria( $field->Bundle, false, false, false ) ) as $rating_name ) {
					$ratings[ $rating_name ] = mt_rand( 1, 5 );
				}
				return array( $ratings );
		}
	}
}
