<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class SBPAI_Module_ACF {
    public function populate_all_fields( $post_id, $type = 'post' ) {
        if ( ! function_exists( 'get_field_objects' ) ) return;

        $fields = get_field_objects( $post_id );
        if ( ! $fields ) return;

        $faker = Faker\Factory::create();

        foreach ( $fields as $field_name => $field ) {
            $value = null;

            switch ( $field['type'] ) {
                case 'text':
                case 'textarea':
                    $value = $faker->sentence();
                    break;
                case 'number':
                    $value = wp_rand( 1, 1000 );
                    break;
                case 'email':
                    $value = $faker->safeEmail;
                    break;
                case 'url':
                    $value = $faker->url;
                    break;
                case 'image':
                    $value = SBPAI_Service_Media::fetch_image();
                    break;
                case 'color_picker':
                    $value = $faker->hexColor;
                    break;
            }

            if ( $value !== null ) {
                update_field( $field['key'], $value, $post_id );
            }
        }
    }
}
