<?php
declare(strict_types=1);

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

namespace Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLQueries;

use Automattic\WooCommerce\Api\Queries\Coupons\GetCoupon as GetCouponCommand;
use Automattic\WooCommerce\Internal\Api\QueryInfoExtractor;
use Automattic\WooCommerce\Internal\Api\Utils;
use Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Output\Coupon as CouponType;
use Automattic\WooCommerce\Internal\Api\Schema\ResolveInfo;
use Automattic\WooCommerce\Internal\Api\Schema\Type;

class GetCoupon {
	public static function get_field_definition(): array {
		return array(
			'type'        => CouponType::get(),
			'description' => __( 'Retrieve a single coupon by ID or code. Exactly one of the two arguments must be provided.', 'woocommerce' ),
			'args'        => array(
				'id'   => array(
					'type'         => Type::int(),
					'description'  => __( 'The ID of the coupon to retrieve.', 'woocommerce' ),
					'defaultValue' => null,
				),
				'code' => array(
					'type'         => Type::string(),
					'description'  => __( 'The coupon code to look up.', 'woocommerce' ),
					'defaultValue' => null,
				),
			),
			'resolve'     => array( self::class, 'resolve' ),
		);
	}

	public static function resolve( mixed $root, array $args, mixed $context, ResolveInfo $info ): mixed {
		Utils::check_current_user_can( 'read_private_shop_coupons' );

		$command = \Automattic\WooCommerce\Api\Container::get( GetCouponCommand::class );

		$execute_args = array();
		if ( array_key_exists( 'id', $args ) ) {
			$execute_args['id'] = $args['id'];
		}
		if ( array_key_exists( 'code', $args ) ) {
			$execute_args['code'] = $args['code'];
		}

		$result = Utils::execute_command( $command, $execute_args );

		return $result;
	}
}
