seed_settings(); $this->seed_statuses(); $staff_id = $this->seed_default_staff(); $location_id = $this->seed_default_location(); $this->seed_staff_location( $staff_id, $location_id ); $this->seed_default_availability( $staff_id, $location_id ); } private function seed_settings(): void { $settings = get_option( 'abientot_settings' ); if ( ! is_array( $settings ) ) { $settings = array(); } $defaults = array( 'delete_data_on_uninstall' => false, 'business_timezone' => wp_timezone_string(), 'currency' => 'USD', 'booking_min_notice_hours' => 24, 'booking_window_days' => 90, 'default_payment_status' => 'unpaid', 'payment_instructions' => __( 'Please pay on site at your appointment.', 'abientot' ), ); update_option( 'abientot_settings', array_merge( $defaults, $settings ), false ); } private function seed_statuses(): void { global $wpdb; $table = $this->table( 'booking_statuses' ); $now = $this->now(); $statuses = array( array( 'pending', 'Pending', '#f59e0b', 1, 0, 1, 1, 10 ), array( 'confirmed', 'Confirmed', '#2563eb', 1, 0, 0, 1, 20 ), array( 'completed', 'Completed', '#16a34a', 1, 1, 0, 1, 30 ), array( 'cancelled', 'Cancelled', '#64748b', 0, 0, 0, 1, 40 ), array( 'no_show', 'No-show', '#dc2626', 0, 0, 0, 1, 50 ), ); foreach ( $statuses as $status ) { $exists = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}abientot_booking_statuses WHERE slug = %s", $status[0] ) ); if ( $exists ) { continue; } $wpdb->insert( $table, array( 'slug' => $status[0], 'label' => $status[1], 'color' => $status[2], 'blocks_availability' => $status[3], 'counts_as_revenue' => $status[4], 'is_default' => $status[5], 'is_system' => $status[6], 'sort_order' => $status[7], 'created_at' => $now, 'updated_at' => $now, ), array( '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%s' ) ); } } private function seed_default_staff(): int { global $wpdb; $table = $this->table( 'staff' ); $id = (int) $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}abientot_staff WHERE is_default = 1 ORDER BY id ASC LIMIT 1" ); if ( $id > 0 ) { return $id; } $now = $this->now(); $wpdb->insert( $table, array( 'display_name' => __( 'Default Staff', 'abientot' ), 'timezone' => wp_timezone_string(), 'is_default' => 1, 'status' => 'active', 'created_at' => $now, 'updated_at' => $now, ), array( '%s', '%s', '%d', '%s', '%s', '%s' ) ); return (int) $wpdb->insert_id; } private function seed_default_location(): int { global $wpdb; $table = $this->table( 'locations' ); $id = (int) $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}abientot_locations WHERE is_default = 1 ORDER BY id ASC LIMIT 1" ); if ( $id > 0 ) { return $id; } $now = $this->now(); $wpdb->insert( $table, array( 'name' => __( 'Default Location', 'abientot' ), 'timezone' => wp_timezone_string(), 'is_default' => 1, 'status' => 'active', 'created_at' => $now, 'updated_at' => $now, ), array( '%s', '%s', '%d', '%s', '%s', '%s' ) ); return (int) $wpdb->insert_id; } private function seed_staff_location( int $staff_id, int $location_id ): void { global $wpdb; if ( $staff_id <= 0 || $location_id <= 0 ) { return; } $table = $this->table( 'staff_locations' ); $exists = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}abientot_staff_locations WHERE staff_id = %d AND location_id = %d", $staff_id, $location_id ) ); if ( $exists ) { return; } $wpdb->insert( $table, array( 'staff_id' => $staff_id, 'location_id' => $location_id, 'created_at' => $this->now(), ), array( '%d', '%d', '%s' ) ); } private function seed_default_availability( int $staff_id, int $location_id ): void { global $wpdb; if ( $staff_id <= 0 ) { return; } $table = $this->table( 'availability_rules' ); $existing = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}abientot_availability_rules WHERE staff_id = %d AND rule_type = %s", $staff_id, 'working' ) ); if ( $existing ) { return; } $now = $this->now(); for ( $weekday = 1; $weekday <= 5; $weekday++ ) { $wpdb->insert( $table, array( 'staff_id' => $staff_id, 'location_id' => $location_id > 0 ? $location_id : null, 'service_id' => null, 'weekday' => $weekday, 'start_time' => '09:00:00', 'end_time' => '17:00:00', 'rule_type' => 'working', 'is_active' => 1, 'created_at' => $now, 'updated_at' => $now, ), array( '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%d', '%s', '%s' ) ); } } private function table( string $suffix ): string { global $wpdb; return $wpdb->prefix . 'abientot_' . $suffix; } private function now(): string { return gmdate( 'Y-m-d H:i:s' ); } }