<?php declare(strict_types = 1);

/**
 * @template-name Shopify Block Registration
 * @template-version 1.0.0
 * @template-description Registers a Shopify block for a given data source.
 * 
 * Template variables:
 * - DATA_SOURCE_UUID: The UUID of the data source to register the block for.
 * - BLOCK_REG_FN_SLUG: The slug of the data source to register the block for.
 */

namespace RemoteDataBlocks\Snippets\Shopify;

use RemoteDataBlocks\Integrations\Shopify\ShopifyDataSource;
use RemoteDataBlocks\Integrations\Shopify\ShopifyIntegration;
use RemoteDataBlocks\WpdbStorage\DataSourceCrud;

function register_shopify__{{BLOCK_REG_FN_SLUG}}__block(): void {
	$data_source_config = DataSourceCrud::get_config_by_uuid( '{{DATA_SOURCE_UUID}}' );
	
	if ( is_wp_error( $data_source_config ) ) {
		return;
	}

	$shopify_data_source = ShopifyDataSource::from_array( $data_source_config );

	ShopifyIntegration::register_blocks_for_shopify_data_source( $shopify_data_source );
}

add_action( 'init', __NAMESPACE__ . '\\register_shopify__{{BLOCK_REG_FN_SLUG}}__block' );
