<?php
/**
 * DESCRIPTION: Generates realistic sample data for events, bookings, payments,
 * and taxonomies. Callable via WP-CLI or admin action.
 *
 * @package NemtlyBooking
 */

namespace NemtlyBooking\Core;

/**
 * Seeder class — populates the database with realistic demo data.
 *
 * @since PBOOKING_SINCE
 */
class Seeder {

    /**
     * Run the full seeder.
     *
     * @since PBOOKING_SINCE
     *
     * @return array Summary of what was created.
     */
    public static function run() {
        $summary = [];

        $summary['categories'] = self::seed_categories();
        $summary['tags']       = self::seed_tags();
        $summary['events']     = self::seed_events();
        $summary['bookings']   = self::seed_bookings();
        $summary['payments']   = self::seed_payments();

        return $summary;
    }

    /**
     * Seed event categories.
     *
     * @since PBOOKING_SINCE
     *
     * @return int Number of categories created.
     */
    public static function seed_categories() {
        $categories = [
            [
                'name'        => 'Workshops',
                'slug'        => 'workshops',
                'description' => 'Hands-on learning sessions where participants gain practical skills.',
            ],
            [
                'name'        => 'Consultations',
                'slug'        => 'consultations',
                'description' => 'One-on-one advisory sessions with subject matter experts.',
            ],
            [
                'name'        => 'Webinars',
                'slug'        => 'webinars',
                'description' => 'Online presentations and live Q&A sessions.',
            ],
            [
                'name'        => 'Fitness',
                'slug'        => 'fitness',
                'description' => 'Exercise classes, yoga sessions, and wellness programs.',
            ],
            [
                'name'        => 'Music & Arts',
                'slug'        => 'music-arts',
                'description' => 'Creative sessions including music lessons, art classes, and performances.',
            ],
            [
                'name'        => 'Health & Wellness',
                'slug'        => 'health-wellness',
                'description' => 'Medical consultations, therapy sessions, and wellness check-ups.',
            ],
            [
                'name'        => 'Community Events',
                'slug'        => 'community-events',
                'description' => 'Local gatherings, meetups, and social events.',
            ],
            [
                'name'        => 'Business',
                'slug'        => 'business',
                'description' => 'Professional development, networking, and corporate events.',
            ],
        ];

        $count = 0;
        foreach ( $categories as $cat ) {
            if ( ! term_exists( $cat['slug'], 'nemtly_event_category' ) ) {
                $result = wp_insert_term(
                    $cat['name'],
                    'nemtly_event_category',
                    [
						'slug'        => $cat['slug'],
						'description' => $cat['description'],
					]
                );

                if ( ! is_wp_error( $result ) ) {
                    ++$count;
                }
            }
        }

        return $count;
    }

    /**
     * Seed event tags.
     *
     * @since PBOOKING_SINCE
     *
     * @return int Number of tags created.
     */
    public static function seed_tags() {
        $tags = [
            'beginner-friendly',
            'advanced',
            'free',
            'paid',
            'online',
            'in-person',
            'recurring',
            'limited-seats',
            'new',
            'popular',
            'weekend',
            'evening',
            'family-friendly',
            'professional',
            'certification',
        ];

        $count = 0;
        foreach ( $tags as $tag ) {
            if ( ! term_exists( $tag, 'nemtly_event_tag' ) ) {
                $result = wp_insert_term(
                    ucwords( str_replace( '-', ' ', $tag ) ),
                    'nemtly_event_tag',
                    [
						'slug' => $tag,
					]
                );

                if ( ! is_wp_error( $result ) ) {
                    ++$count;
                }
            }
        }

        return $count;
    }

    /**
     * Seed events across all three types.
     *
     * @since PBOOKING_SINCE
     *
     * @return int Number of events created.
     */
    public static function seed_events() {
        $events = self::get_event_definitions();
        $count  = 0;

        foreach ( $events as $event ) {
            $post_id = self::create_event( $event );
            if ( $post_id && ! is_wp_error( $post_id ) ) {
                ++$count;
            }
        }

        return $count;
    }

    /**
     * Create a single event with all its meta and taxonomy terms.
     *
     * @since PBOOKING_SINCE
     *
     * @param array $event Event definition array.
     *
     * @return int|\WP_Error Post ID or error.
     */
    private static function create_event( $event ) {
        $post_id = wp_insert_post(
            [
				'post_title'   => $event['title'],
				'post_content' => $event['description'],
				'post_type'    => 'nemtly_event',
				'post_status'  => $event['post_status'] ?? 'publish',
				'post_author'  => get_current_user_id() ? get_current_user_id() : 1,
			]
        );

        if ( is_wp_error( $post_id ) || 0 === $post_id ) {
            return $post_id;
        }

        // Compute UTC from local time.
        $timezone = $event['timezone'] ?? 'America/New_York';
        $utc      = Event_Creator::compute_utc(
            $event['event_date'] ?? '',
            $event['event_time'] ?? '',
            $timezone
        );

        $meta = [
            Event_Creator::META_EVENT_DATE         => $event['event_date'] ?? '',
            Event_Creator::META_EVENT_TIME         => $event['event_time'] ?? '',
            Event_Creator::META_EVENT_DATE_UTC     => $utc['date'],
            Event_Creator::META_EVENT_TIME_UTC     => $utc['time'],
            Event_Creator::META_EVENT_TIMEZONE     => $timezone,
            Event_Creator::META_EVENT_END_DATE     => $event['event_end_date'] ?? '',
            Event_Creator::META_EVENT_END_TIME     => $event['event_end_time'] ?? '',
            Event_Creator::META_EVENT_DURATION     => $event['duration'] ?? 60,
            Event_Creator::META_LOCATION           => $event['location'] ?? '',
            Event_Creator::META_MAX_ATTENDEES      => $event['max_attendees'] ?? 0,
            Event_Creator::META_BOOKING_CUTOFF     => $event['booking_cutoff'] ?? 2,
            Event_Creator::META_ALLOW_WAITLIST     => $event['allow_waitlist'] ?? false,
            Event_Creator::META_RECURRENCE_PATTERN => $event['recurrence_pattern'] ?? 'none',
            Event_Creator::META_RECURRENCE_COUNT   => $event['recurrence_count'] ?? 1,
            Event_Creator::META_RECURRENCE_END     => $event['recurrence_end'] ?? '',
            Event_Creator::META_IS_RECURRING       => $event['is_recurring'] ?? false,
            Event_Creator::META_PRICE              => $event['price'] ?? 0,
            Event_Creator::META_BUFFER_BEFORE      => $event['buffer_before'] ?? 0,
            Event_Creator::META_BUFFER_AFTER       => $event['buffer_after'] ?? 0,
            Event_Creator::META_EVENT_TYPE         => $event['event_type'] ?? 'one-on-one',
            Event_Creator::META_AVAILABILITY       => wp_json_encode( $event['availability'] ?? [] ),
        ];

        foreach ( $meta as $key => $value ) {
            update_post_meta( $post_id, $key, $value );
        }

        // Assign taxonomy terms.
        if ( ! empty( $event['categories'] ) ) {
            wp_set_object_terms( $post_id, $event['categories'], 'nemtly_event_category' );
        }
        if ( ! empty( $event['tags'] ) ) {
            wp_set_object_terms( $post_id, $event['tags'], 'nemtly_event_tag' );
        }

        // Stash post_id so bookings can reference it.
        $event['_post_id'] = $post_id;

        return $post_id;
    }

    /**
     * Seed bookings across the created events.
     *
     * @since PBOOKING_SINCE
     *
     * @return int Number of bookings created.
     */
    public static function seed_bookings() {
        global $wpdb;

        $table  = $wpdb->prefix . NEMTLY_BOOKING_TABLE_BOOKINGS;
        $events = get_posts(
            [
				'post_type'      => 'nemtly_event',
				'post_status'    => 'publish',
				'posts_per_page' => -1,
				'fields'         => 'ids',
			]
        );

        if ( empty( $events ) ) {
            return 0;
        }

        $attendees = self::get_attendee_list();
        $statuses  = [ 'confirmed', 'confirmed', 'confirmed', 'pending', 'cancelled', 'rejected' ];
        $count     = 0;

        foreach ( $events as $event_id ) {
            $event_date = get_post_meta( $event_id, Event_Creator::META_EVENT_DATE, true );
            $event_time = get_post_meta( $event_id, Event_Creator::META_EVENT_TIME, true );
            $duration   = (int) get_post_meta( $event_id, Event_Creator::META_EVENT_DURATION, true );
            $event_type = get_post_meta( $event_id, Event_Creator::META_EVENT_TYPE, true );

            // Determine how many bookings per event.
            switch ( $event_type ) {
                case 'one-on-one':
                    $num_bookings = wp_rand( 1, 2 );
                    break;
                case 'group':
                    $num_bookings = wp_rand( 3, 8 );
                    break;
                case 'event':
                default:
                    $num_bookings = wp_rand( 5, 15 );
                    break;
            }

            for ( $i = 0; $i < $num_bookings; $i++ ) {
                $attendee      = $attendees[ array_rand( $attendees ) ];
                $status        = $statuses[ array_rand( $statuses ) ];
                $booking_date  = $event_date ? $event_date : gmdate( 'Y-m-d' );
                $booking_start = $booking_date . ' ' . ( $event_time ? $event_time : '09:00' ) . ':00';
                $end_minutes   = $duration ? $duration : 60;
                $start_ts      = strtotime( $booking_start );
                $booking_end   = gmdate( 'Y-m-d H:i:s', $start_ts + ( $end_minutes * 60 ) );
                $days_ago      = wp_rand( 1, 30 );
                $created_at    = gmdate( 'Y-m-d H:i:s', strtotime( "-{$days_ago} days" ) );

                $wpdb->insert(
                    $table,
                    [
                        'event_id'       => $event_id,
                        'user_id'        => $attendee['user_id'],
                        'booking_uuid'   => wp_generate_uuid4(),
                        'booking_status' => $status,
                        'attendee_name'  => $attendee['name'],
                        'attendee_email' => $attendee['email'],
                        'attendee_phone' => $attendee['phone'],
                        'booking_date'   => $booking_date,
                        'booking_start'  => $booking_start,
                        'booking_end'    => $booking_end,
                        'booking_meta'   => wp_json_encode(
                            [
								'source'           => 'seeder',
								'special_requests' => $attendee['notes'],
							]
                        ),
                        'created_at'     => $created_at,
                        'updated_at'     => $created_at,
                    ],
                    [ '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ]
                );

                if ( $wpdb->insert_id ) {
                    ++$count;
                }
            }
        }

        return $count;
    }

    /**
     * Seed payments for confirmed bookings.
     *
     * @since PBOOKING_SINCE
     *
     * @return int Number of payments created.
     */
    public static function seed_payments() {
        global $wpdb;

        $bookings_table = $wpdb->prefix . NEMTLY_BOOKING_TABLE_BOOKINGS;
        $payments_table = $wpdb->prefix . NEMTLY_BOOKING_TABLE_PAYMENTS;

        // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
        $bookings = $wpdb->get_results(
            "SELECT b.id AS booking_id, b.event_id, b.booking_status, b.created_at
             FROM {$bookings_table} b"
        );
        // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared

        if ( empty( $bookings ) ) {
            return 0;
        }

        $count = 0;

        foreach ( $bookings as $booking ) {
            $event_price = (float) get_post_meta( $booking->event_id, Event_Creator::META_PRICE, true );

            // Free events don't need payments.
            if ( $event_price <= 0 ) {
                continue;
            }

            // Determine payment status based on booking status.
            switch ( $booking->booking_status ) {
                case 'confirmed':
                    $payment_status = 'succeeded';
                    break;
                case 'pending':
                    $payment_status = 'pending';
                    break;
                case 'cancelled':
                    // Some cancelled bookings were refunded, some failed.
                    $payment_status = wp_rand( 0, 1 ) ? 'refunded' : 'failed';
                    break;
                case 'rejected':
                    $payment_status = 'failed';
                    break;
                default:
                    $payment_status = 'pending';
                    break;
            }

            $currencies     = [ 'USD', 'USD', 'USD', 'EUR', 'GBP' ];
            $currency       = $currencies[ array_rand( $currencies ) ];
            $transaction_id = 'pi_' . bin2hex( random_bytes( 12 ) );

            $wpdb->insert(
                $payments_table,
                [
                    'payable_id'       => $booking->booking_id,
                    'payable_type'     => 'booking',
                    'booking_id'       => $booking->booking_id,
                    'transaction_id'   => $transaction_id,
                    'amount'           => $event_price,
                    'currency'         => $currency,
                    'status'           => $payment_status,
                    'gateway'          => 'stripe',
                    'gateway_response' => wp_json_encode(
                        [
							'id'       => $transaction_id,
							'object'   => 'payment_intent',
							'status'   => $payment_status,
							'amount'   => (int) ( $event_price * 100 ),
							'currency' => strtolower( $currency ),
						]
                    ),
                    'created_at'       => $booking->created_at,
                    'updated_at'       => $booking->created_at,
                ],
                [ '%d', '%s', '%d', '%s', '%f', '%s', '%s', '%s', '%s', '%s', '%s' ]
            );

            if ( $wpdb->insert_id ) {
                ++$count;
            }
        }

        return $count;
    }

    /**
     * Remove all seeded data. Useful for resetting.
     *
     * @since PBOOKING_SINCE
     *
     * @return array Summary of what was deleted.
     */
    public static function reset() {
        global $wpdb;

        // Delete all bookings and payments.
        $bookings_table = $wpdb->prefix . NEMTLY_BOOKING_TABLE_BOOKINGS;
        $payments_table = $wpdb->prefix . NEMTLY_BOOKING_TABLE_PAYMENTS;

        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
        $payments_deleted = $wpdb->query( "TRUNCATE TABLE {$payments_table}" );
        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
        $bookings_deleted = $wpdb->query( "TRUNCATE TABLE {$bookings_table}" );

        // Delete all events.
        $events = get_posts(
            [
				'post_type'      => 'nemtly_event',
				'post_status'    => 'any',
				'posts_per_page' => -1,
				'fields'         => 'ids',
			]
        );

        foreach ( $events as $event_id ) {
            wp_delete_post( $event_id, true );
        }

        // Delete taxonomy terms.
        $taxonomies = [ 'nemtly_event_category', 'nemtly_event_tag' ];
        foreach ( $taxonomies as $taxonomy ) {
            $terms = get_terms(
                [
					'taxonomy'   => $taxonomy,
					'hide_empty' => false,
					'fields'     => 'ids',
				]
            );

            if ( ! is_wp_error( $terms ) ) {
                foreach ( $terms as $term_id ) {
                    wp_delete_term( $term_id, $taxonomy );
                }
            }
        }

        return [
            'events_deleted'   => count( $events ),
            'bookings_deleted' => false !== $bookings_deleted,
            'payments_deleted' => false !== $payments_deleted,
        ];
    }

    /**
     * Get event definitions for seeding.
     *
     * @since PBOOKING_SINCE
     *
     * @return array List of event definition arrays.
     */
    private static function get_event_definitions() {
        $base_date = gmdate( 'Y-m-d', strtotime( '+3 days' ) );

        return [
            // === ONE-ON-ONE EVENTS ===
            [
                'title'              => 'Career Coaching Session',
                'description'        => 'Personal 1-on-1 career coaching with a certified professional coach. We\'ll review your resume, discuss career goals, and build an actionable plan for your next move.',
                'event_type'         => 'one-on-one',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+5 days' ) ),
                'event_time'         => '10:00',
                'timezone'           => 'America/New_York',
                'duration'           => 45,
                'location'           => 'Zoom (link sent after booking)',
                'max_attendees'      => 1,
                'booking_cutoff'     => 4,
                'allow_waitlist'     => false,
                'price'              => 85.00,
                'buffer_before'      => 0,
                'buffer_after'       => 15,
                'recurrence_pattern' => 'availability',
                'is_recurring'       => true,
                'availability'       => [
                    'mon' => [
						[
							'start' => '09:00',
							'end'   => '12:00',
						],
						[
							'start' => '14:00',
							'end'   => '17:00',
						],
					],
                    'tue' => [
						[
							'start' => '09:00',
							'end'   => '12:00',
						],
					],
                    'wed' => [
						[
							'start' => '09:00',
							'end'   => '12:00',
						],
						[
							'start' => '14:00',
							'end'   => '17:00',
						],
					],
                    'thu' => [
						[
							'start' => '10:00',
							'end'   => '16:00',
						],
					],
                    'fri' => [
						[
							'start' => '09:00',
							'end'   => '12:00',
						],
					],
                    'sat' => [],
                    'sun' => [],
                ],
                'categories'         => [ 'consultations', 'business' ],
                'tags'               => [ 'online', 'professional', 'paid' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'Nutrition Consultation',
                'description'        => 'Meet with a registered dietitian for a personalized nutrition assessment. Includes a customized meal plan and supplement recommendations tailored to your health goals.',
                'event_type'         => 'one-on-one',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+4 days' ) ),
                'event_time'         => '11:00',
                'timezone'           => 'America/Chicago',
                'duration'           => 30,
                'location'           => 'Wellness Center, 456 Health Ave, Suite 201',
                'max_attendees'      => 1,
                'booking_cutoff'     => 2,
                'allow_waitlist'     => false,
                'price'              => 120.00,
                'buffer_before'      => 0,
                'buffer_after'       => 15,
                'recurrence_pattern' => 'availability',
                'is_recurring'       => true,
                'availability'       => [
                    'mon' => [
						[
							'start' => '08:00',
							'end'   => '12:00',
						],
					],
                    'tue' => [
						[
							'start' => '08:00',
							'end'   => '12:00',
						],
					],
                    'wed' => [],
                    'thu' => [
						[
							'start' => '13:00',
							'end'   => '17:00',
						],
					],
                    'fri' => [
						[
							'start' => '08:00',
							'end'   => '12:00',
						],
					],
                    'sat' => [
						[
							'start' => '09:00',
							'end'   => '12:00',
						],
					],
                    'sun' => [],
                ],
                'categories'         => [ 'consultations', 'health-wellness' ],
                'tags'               => [ 'in-person', 'paid' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'Guitar Lesson — Beginner',
                'description'        => 'Private guitar lessons for beginners. Learn chords, strumming patterns, and your first songs. Acoustic or electric — bring your own instrument or borrow one of ours.',
                'event_type'         => 'one-on-one',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+7 days' ) ),
                'event_time'         => '15:00',
                'timezone'           => 'America/Los_Angeles',
                'duration'           => 60,
                'location'           => 'Harmony Music Studio, 789 Melody Ln',
                'max_attendees'      => 1,
                'booking_cutoff'     => 6,
                'allow_waitlist'     => false,
                'price'              => 55.00,
                'buffer_before'      => 5,
                'buffer_after'       => 10,
                'recurrence_pattern' => 'availability',
                'is_recurring'       => true,
                'availability'       => [
                    'mon' => [
						[
							'start' => '14:00',
							'end'   => '20:00',
						],
					],
                    'tue' => [
						[
							'start' => '14:00',
							'end'   => '20:00',
						],
					],
                    'wed' => [
						[
							'start' => '14:00',
							'end'   => '20:00',
						],
					],
                    'thu' => [
						[
							'start' => '14:00',
							'end'   => '20:00',
						],
					],
                    'fri' => [
						[
							'start' => '14:00',
							'end'   => '18:00',
						],
					],
                    'sat' => [
						[
							'start' => '10:00',
							'end'   => '16:00',
						],
					],
                    'sun' => [],
                ],
                'categories'         => [ 'music-arts' ],
                'tags'               => [ 'in-person', 'beginner-friendly', 'paid' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'Tax Planning Consultation',
                'description'        => 'One-on-one session with a CPA to review your tax situation, identify deductions, and plan for the upcoming filing season. Bring your recent pay stubs and last year\'s return.',
                'event_type'         => 'one-on-one',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+6 days' ) ),
                'event_time'         => '09:00',
                'timezone'           => 'America/New_York',
                'duration'           => 60,
                'location'           => 'Financial District Office, 100 Wall St, Floor 12',
                'max_attendees'      => 1,
                'booking_cutoff'     => 24,
                'allow_waitlist'     => false,
                'price'              => 150.00,
                'buffer_before'      => 0,
                'buffer_after'       => 15,
                'recurrence_pattern' => 'availability',
                'is_recurring'       => true,
                'availability'       => [
                    'mon' => [
						[
							'start' => '09:00',
							'end'   => '17:00',
						],
					],
                    'tue' => [
						[
							'start' => '09:00',
							'end'   => '17:00',
						],
					],
                    'wed' => [
						[
							'start' => '09:00',
							'end'   => '12:00',
						],
					],
                    'thu' => [
						[
							'start' => '09:00',
							'end'   => '17:00',
						],
					],
                    'fri' => [
						[
							'start' => '09:00',
							'end'   => '14:00',
						],
					],
                    'sat' => [],
                    'sun' => [],
                ],
                'categories'         => [ 'consultations', 'business' ],
                'tags'               => [ 'in-person', 'professional', 'paid' ],
                'post_status'        => 'publish',
            ],

            // === GROUP EVENTS ===
            [
                'title'              => 'Morning Yoga Flow',
                'description'        => 'Start your day with a rejuvenating vinyasa flow class. All levels welcome. Mats provided but feel free to bring your own. Wear comfortable clothing and arrive 10 minutes early.',
                'event_type'         => 'group',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+2 days' ) ),
                'event_time'         => '07:00',
                'timezone'           => 'America/New_York',
                'duration'           => 60,
                'location'           => 'Serenity Yoga Studio, 321 Zen Blvd',
                'max_attendees'      => 15,
                'booking_cutoff'     => 2,
                'allow_waitlist'     => true,
                'price'              => 20.00,
                'buffer_before'      => 0,
                'buffer_after'       => 15,
                'recurrence_pattern' => 'availability',
                'is_recurring'       => true,
                'availability'       => [
                    'mon' => [
						[
							'start' => '07:00',
							'end'   => '08:00',
						],
					],
                    'tue' => [],
                    'wed' => [
						[
							'start' => '07:00',
							'end'   => '08:00',
						],
					],
                    'thu' => [],
                    'fri' => [
						[
							'start' => '07:00',
							'end'   => '08:00',
						],
					],
                    'sat' => [
						[
							'start' => '08:00',
							'end'   => '09:00',
						],
					],
                    'sun' => [],
                ],
                'categories'         => [ 'fitness', 'health-wellness' ],
                'tags'               => [ 'beginner-friendly', 'recurring', 'in-person', 'paid' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'Watercolor Painting Workshop',
                'description'        => 'Learn watercolor fundamentals — color mixing, wet-on-wet technique, and landscape composition. All materials included. No experience necessary. Take home your finished piece!',
                'event_type'         => 'group',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+10 days' ) ),
                'event_time'         => '14:00',
                'timezone'           => 'America/Chicago',
                'duration'           => 120,
                'location'           => 'The Creative Loft, 555 Art District Way',
                'max_attendees'      => 12,
                'booking_cutoff'     => 24,
                'allow_waitlist'     => true,
                'price'              => 45.00,
                'buffer_before'      => 0,
                'buffer_after'       => 30,
                'recurrence_pattern' => 'none',
                'is_recurring'       => false,
                'availability'       => [],
                'categories'         => [ 'workshops', 'music-arts' ],
                'tags'               => [ 'beginner-friendly', 'in-person', 'paid', 'weekend' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'Public Speaking Bootcamp',
                'description'        => 'Overcome stage fright and sharpen your presentation skills in this intensive group workshop. Practice impromptu speaking, storytelling techniques, and audience engagement strategies.',
                'event_type'         => 'group',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+14 days' ) ),
                'event_time'         => '10:00',
                'timezone'           => 'America/New_York',
                'duration'           => 180,
                'location'           => 'Downtown Conference Center, Room 4B',
                'max_attendees'      => 20,
                'booking_cutoff'     => 48,
                'allow_waitlist'     => true,
                'price'              => 75.00,
                'buffer_before'      => 0,
                'buffer_after'       => 0,
                'recurrence_pattern' => 'none',
                'is_recurring'       => false,
                'availability'       => [],
                'categories'         => [ 'workshops', 'business' ],
                'tags'               => [ 'in-person', 'professional', 'paid', 'certification' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'Intro to Python Programming',
                'description'        => 'A beginner-friendly group class covering Python basics — variables, loops, functions, and a mini-project. Bring your laptop with Python 3.10+ installed.',
                'event_type'         => 'group',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+8 days' ) ),
                'event_time'         => '18:00',
                'timezone'           => 'America/Los_Angeles',
                'duration'           => 90,
                'location'           => 'TechHub Coworking, 900 Innovation Dr',
                'max_attendees'      => 25,
                'booking_cutoff'     => 12,
                'allow_waitlist'     => true,
                'price'              => 0.00,
                'buffer_before'      => 0,
                'buffer_after'       => 0,
                'recurrence_pattern' => 'weekly',
                'recurrence_count'   => 6,
                'recurrence_end'     => gmdate( 'Y-m-d', strtotime( '+50 days' ) ),
                'is_recurring'       => true,
                'availability'       => [
                    'mon' => [],
                    'tue' => [
						[
							'start' => '18:00',
							'end'   => '19:30',
						],
					],
                    'wed' => [],
                    'thu' => [],
                    'fri' => [],
                    'sat' => [],
                    'sun' => [],
                ],
                'categories'         => [ 'workshops' ],
                'tags'               => [ 'beginner-friendly', 'free', 'in-person', 'recurring' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'HIIT Circuit Training',
                'description'        => 'High-intensity interval training for intermediate to advanced fitness levels. 45-minute circuit with strength and cardio stations. Water and towels provided.',
                'event_type'         => 'group',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+3 days' ) ),
                'event_time'         => '06:30',
                'timezone'           => 'America/New_York',
                'duration'           => 45,
                'location'           => 'Iron Forge Gym, 222 Power St',
                'max_attendees'      => 20,
                'booking_cutoff'     => 1,
                'allow_waitlist'     => false,
                'price'              => 15.00,
                'buffer_before'      => 0,
                'buffer_after'       => 15,
                'recurrence_pattern' => 'availability',
                'is_recurring'       => true,
                'availability'       => [
                    'mon' => [
						[
							'start' => '06:30',
							'end'   => '07:15',
						],
					],
                    'tue' => [],
                    'wed' => [
						[
							'start' => '06:30',
							'end'   => '07:15',
						],
					],
                    'thu' => [],
                    'fri' => [
						[
							'start' => '06:30',
							'end'   => '07:15',
						],
					],
                    'sat' => [],
                    'sun' => [],
                ],
                'categories'         => [ 'fitness' ],
                'tags'               => [ 'advanced', 'in-person', 'paid', 'recurring' ],
                'post_status'        => 'publish',
            ],

            // === FULL-DAY / DATE-BASED EVENTS ===
            [
                'title'              => 'Annual Community BBQ & Music Festival',
                'description'        => 'Join your neighbors for the annual summer BBQ! Live music from three local bands, a kids\' zone with face painting and games, local food vendors, and a craft beer garden. Free entry — food and drinks sold separately.',
                'event_type'         => 'event',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+21 days' ) ),
                'event_time'         => '11:00',
                'event_end_date'     => gmdate( 'Y-m-d', strtotime( '+21 days' ) ),
                'event_end_time'     => '20:00',
                'timezone'           => 'America/New_York',
                'duration'           => 540,
                'location'           => 'Riverside Park, Main Pavilion',
                'max_attendees'      => 0,
                'booking_cutoff'     => 0,
                'allow_waitlist'     => false,
                'price'              => 0.00,
                'buffer_before'      => 0,
                'buffer_after'       => 0,
                'recurrence_pattern' => 'none',
                'is_recurring'       => false,
                'availability'       => [],
                'categories'         => [ 'community-events', 'music-arts' ],
                'tags'               => [ 'free', 'family-friendly', 'in-person' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'Startup Pitch Night',
                'description'        => 'Watch 8 early-stage startups pitch to a panel of angel investors and VCs. Network over drinks after the presentations. Limited seating — RSVP required.',
                'event_type'         => 'event',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+12 days' ) ),
                'event_time'         => '18:30',
                'event_end_date'     => gmdate( 'Y-m-d', strtotime( '+12 days' ) ),
                'event_end_time'     => '21:30',
                'timezone'           => 'America/New_York',
                'duration'           => 180,
                'location'           => 'Innovation Hub, 50 Startup Row, 3rd Floor',
                'max_attendees'      => 150,
                'booking_cutoff'     => 48,
                'allow_waitlist'     => true,
                'price'              => 10.00,
                'buffer_before'      => 0,
                'buffer_after'       => 0,
                'recurrence_pattern' => 'none',
                'is_recurring'       => false,
                'availability'       => [],
                'categories'         => [ 'business', 'community-events' ],
                'tags'               => [ 'in-person', 'paid', 'professional', 'limited-seats', 'evening' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'WordPress Developer Meetup',
                'description'        => 'Monthly WordPress developer meetup. This month\'s topic: building custom blocks with the Interactivity API. Lightning talks welcome — sign up at the door. Pizza and beverages provided.',
                'event_type'         => 'event',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+18 days' ) ),
                'event_time'         => '19:00',
                'event_end_date'     => gmdate( 'Y-m-d', strtotime( '+18 days' ) ),
                'event_end_time'     => '21:00',
                'timezone'           => 'America/Chicago',
                'duration'           => 120,
                'location'           => 'Public Library, Community Room B',
                'max_attendees'      => 40,
                'booking_cutoff'     => 2,
                'allow_waitlist'     => true,
                'price'              => 0.00,
                'buffer_before'      => 0,
                'buffer_after'       => 0,
                'recurrence_pattern' => 'monthly',
                'recurrence_count'   => 6,
                'recurrence_end'     => gmdate( 'Y-m-d', strtotime( '+180 days' ) ),
                'is_recurring'       => true,
                'availability'       => [],
                'categories'         => [ 'community-events' ],
                'tags'               => [ 'free', 'in-person', 'professional', 'recurring' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'AI in Healthcare — Live Webinar',
                'description'        => 'Join Dr. Sarah Chen and a panel of healthcare AI researchers for a deep dive into how machine learning is transforming diagnostics, drug discovery, and patient care. Q&A included.',
                'event_type'         => 'event',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+9 days' ) ),
                'event_time'         => '13:00',
                'event_end_date'     => gmdate( 'Y-m-d', strtotime( '+9 days' ) ),
                'event_end_time'     => '14:30',
                'timezone'           => 'America/New_York',
                'duration'           => 90,
                'location'           => 'Zoom Webinar (link emailed 1 hour before)',
                'max_attendees'      => 500,
                'booking_cutoff'     => 1,
                'allow_waitlist'     => false,
                'price'              => 0.00,
                'buffer_before'      => 0,
                'buffer_after'       => 0,
                'recurrence_pattern' => 'none',
                'is_recurring'       => false,
                'availability'       => [],
                'categories'         => [ 'webinars', 'health-wellness' ],
                'tags'               => [ 'free', 'online', 'popular' ],
                'post_status'        => 'publish',
            ],
            [
                'title'              => 'Spring Charity 5K Run',
                'description'        => 'Lace up for a good cause! All proceeds go to the local food bank. Chip-timed, with awards for top 3 in each age group. Packet pickup available the day before at Elm Street Recreation Center.',
                'event_type'         => 'event',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+28 days' ) ),
                'event_time'         => '08:00',
                'event_end_date'     => gmdate( 'Y-m-d', strtotime( '+28 days' ) ),
                'event_end_time'     => '11:00',
                'timezone'           => 'America/New_York',
                'duration'           => 180,
                'location'           => 'Elm Street Recreation Center — Starting Line',
                'max_attendees'      => 300,
                'booking_cutoff'     => 72,
                'allow_waitlist'     => true,
                'price'              => 25.00,
                'buffer_before'      => 0,
                'buffer_after'       => 0,
                'recurrence_pattern' => 'none',
                'is_recurring'       => false,
                'availability'       => [],
                'categories'         => [ 'community-events', 'fitness' ],
                'tags'               => [ 'in-person', 'paid', 'family-friendly', 'popular' ],
                'post_status'        => 'publish',
            ],

            // A couple of draft events for realism.
            [
                'title'              => 'Advanced Photography Masterclass',
                'description'        => 'Three-hour deep dive into manual exposure, composition rules, and post-processing in Lightroom. DSLR or mirrorless camera required.',
                'event_type'         => 'group',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+30 days' ) ),
                'event_time'         => '10:00',
                'timezone'           => 'America/New_York',
                'duration'           => 180,
                'location'           => 'Studio 88, Downtown Arts District',
                'max_attendees'      => 10,
                'booking_cutoff'     => 48,
                'allow_waitlist'     => false,
                'price'              => 95.00,
                'buffer_before'      => 0,
                'buffer_after'       => 0,
                'recurrence_pattern' => 'none',
                'is_recurring'       => false,
                'availability'       => [],
                'categories'         => [ 'workshops', 'music-arts' ],
                'tags'               => [ 'advanced', 'in-person', 'paid' ],
                'post_status'        => 'draft',
            ],
            [
                'title'              => 'Meditation & Breathwork Circle',
                'description'        => 'Guided group meditation and breathwork for stress relief. Suitable for complete beginners. Sessions held in a quiet, candle-lit space.',
                'event_type'         => 'group',
                'event_date'         => gmdate( 'Y-m-d', strtotime( '+15 days' ) ),
                'event_time'         => '19:00',
                'timezone'           => 'America/Los_Angeles',
                'duration'           => 60,
                'location'           => 'Mindful Space, 44 Calm Ave',
                'max_attendees'      => 8,
                'booking_cutoff'     => 2,
                'allow_waitlist'     => true,
                'price'              => 0.00,
                'buffer_before'      => 0,
                'buffer_after'       => 10,
                'recurrence_pattern' => 'weekly',
                'recurrence_count'   => 8,
                'recurrence_end'     => gmdate( 'Y-m-d', strtotime( '+71 days' ) ),
                'is_recurring'       => true,
                'availability'       => [
                    'mon' => [],
                    'tue' => [],
                    'wed' => [
						[
							'start' => '19:00',
							'end'   => '20:00',
						],
					],
                    'thu' => [],
                    'fri' => [],
                    'sat' => [],
                    'sun' => [],
                ],
                'categories'         => [ 'health-wellness' ],
                'tags'               => [ 'free', 'beginner-friendly', 'in-person', 'recurring', 'evening' ],
                'post_status'        => 'draft',
            ],
        ];
    }

    /**
     * Get realistic attendee data for booking generation.
     *
     * @since PBOOKING_SINCE
     *
     * @return array List of attendee arrays.
     */
    private static function get_attendee_list() {
        return [
            [
                'name'    => 'Emily Rodriguez',
                'email'   => 'emily.rodriguez@example.com',
                'phone'   => '(555) 234-5678',
                'user_id' => null,
                'notes'   => 'First-time attendee.',
            ],
            [
                'name'    => 'James Chen',
                'email'   => 'james.chen@example.com',
                'phone'   => '(555) 345-6789',
                'user_id' => null,
                'notes'   => '',
            ],
            [
                'name'    => 'Aisha Patel',
                'email'   => 'aisha.patel@example.com',
                'phone'   => '(555) 456-7890',
                'user_id' => null,
                'notes'   => 'Requires wheelchair-accessible seating.',
            ],
            [
                'name'    => 'Marcus Thompson',
                'email'   => 'marcus.t@example.com',
                'phone'   => '',
                'user_id' => null,
                'notes'   => '',
            ],
            [
                'name'    => 'Sofia Andersson',
                'email'   => 'sofia.a@example.com',
                'phone'   => '(555) 567-8901',
                'user_id' => null,
                'notes'   => 'Vegetarian meal preference.',
            ],
            [
                'name'    => 'David Kim',
                'email'   => 'david.kim@example.com',
                'phone'   => '(555) 678-9012',
                'user_id' => null,
                'notes'   => '',
            ],
            [
                'name'    => 'Olivia Martinez',
                'email'   => 'olivia.m@example.com',
                'phone'   => '',
                'user_id' => null,
                'notes'   => 'Bringing a friend (separate booking).',
            ],
            [
                'name'    => 'Liam O\'Brien',
                'email'   => 'liam.obrien@example.com',
                'phone'   => '(555) 789-0123',
                'user_id' => null,
                'notes'   => '',
            ],
            [
                'name'    => 'Fatima Al-Rashidi',
                'email'   => 'fatima.r@example.com',
                'phone'   => '(555) 890-1234',
                'user_id' => null,
                'notes'   => 'Morning sessions preferred.',
            ],
            [
                'name'    => 'Noah Williams',
                'email'   => 'noah.w@example.com',
                'phone'   => '(555) 901-2345',
                'user_id' => null,
                'notes'   => '',
            ],
            [
                'name'    => 'Priya Sharma',
                'email'   => 'priya.sharma@example.com',
                'phone'   => '(555) 012-3456',
                'user_id' => null,
                'notes'   => 'Has completed beginner course.',
            ],
            [
                'name'    => 'Tyler Jackson',
                'email'   => 'tyler.j@example.com',
                'phone'   => '',
                'user_id' => null,
                'notes'   => '',
            ],
            [
                'name'    => 'Hannah Lee',
                'email'   => 'hannah.lee@example.com',
                'phone'   => '(555) 123-4567',
                'user_id' => null,
                'notes'   => 'Interested in the advanced track.',
            ],
            [
                'name'    => 'Carlos Gutierrez',
                'email'   => 'carlos.g@example.com',
                'phone'   => '(555) 234-8901',
                'user_id' => null,
                'notes'   => '',
            ],
            [
                'name'    => 'Mei Lin Wong',
                'email'   => 'meilin.w@example.com',
                'phone'   => '(555) 345-9012',
                'user_id' => null,
                'notes'   => 'Allergic to latex — please note for any craft supplies.',
            ],
        ];
    }
}
