<?php
declare(strict_types=1);

// THIS FILE IS AUTO-GENERATED. DO NOT EDIT MANUALLY.

namespace Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Scalars;

use Automattic\WooCommerce\Api\Scalars\DateTime as DateTimeScalar;
use Automattic\WooCommerce\Internal\Api\Schema\CustomScalarType;

class DateTime {
	private static ?CustomScalarType $instance = null;

	public static function get(): CustomScalarType {
		if ( null === self::$instance ) {
			self::$instance = new CustomScalarType(
				array(
					'name'         => 'DateTime',
					'description'  => __( 'An ISO 8601 encoded date and time string.', 'woocommerce' ),
					'serialize'    => fn( $value ) => DateTimeScalar::serialize( $value ),
					'parseValue'   => function ( $value ) {
						try {
							return DateTimeScalar::parse( $value );
						} catch ( \InvalidArgumentException $e ) {
							throw new \Automattic\WooCommerce\Internal\Api\Schema\Error( $e->getMessage() );
						}
					},
					'parseLiteral' => function ( $value_node, ?array $variables = null ) {
						if ( $value_node instanceof \Automattic\WooCommerce\Internal\Api\Schema\AST\StringValueNode ) {
							try {
								return DateTimeScalar::parse( $value_node->value );
							} catch ( \InvalidArgumentException $e ) {
								throw new \Automattic\WooCommerce\Internal\Api\Schema\Error( $e->getMessage() );
							}
						}
						throw new \Automattic\WooCommerce\Internal\Api\Schema\Error(
							'DateTime must be a string, got: ' . $value_node->kind
						);
					},
				)
			);
		}
		return self::$instance;
	}
}
