<?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\ListCoupons as ListCouponsCommand;
use Automattic\WooCommerce\Internal\Api\QueryInfoExtractor;
use Automattic\WooCommerce\Internal\Api\Utils;
use Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Pagination\CouponConnection as CouponConnectionType;
use Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Enums\CouponStatus as CouponStatusType;
use Automattic\WooCommerce\Internal\Api\Schema\ResolveInfo;
use Automattic\WooCommerce\Internal\Api\Schema\Type;

class ListCoupons {
	public static function get_field_definition(): array {
		return array(
			'type'        => Type::nonNull( CouponConnectionType::get() ),
			'description' => __( 'List coupons with cursor-based pagination.', 'woocommerce' ),
			'args'        => array(
				'first'  => array(
					'type'         => Type::int(),
					'description'  => __( 'Return the first N results. Must be between 0 and 100.', 'woocommerce' ),
					'defaultValue' => null,
				),
				'last'   => array(
					'type'         => Type::int(),
					'description'  => __( 'Return the last N results. Must be between 0 and 100.', 'woocommerce' ),
					'defaultValue' => null,
				),
				'after'  => array(
					'type'         => Type::string(),
					'description'  => __( 'Return results after this cursor.', 'woocommerce' ),
					'defaultValue' => null,
				),
				'before' => array(
					'type'         => Type::string(),
					'description'  => __( 'Return results before this cursor.', 'woocommerce' ),
					'defaultValue' => null,
				),
				'status' => array(
					'type'         => CouponStatusType::get(),
					'description'  => __( 'Filter by coupon status.', 'woocommerce' ),
					'defaultValue' => null,
				),
			),
			'complexity'  => Utils::complexity_from_pagination( ... ),
			'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( ListCouponsCommand::class );

		$execute_args               = array();
		$execute_args['pagination'] = Utils::create_pagination_params( $args );
		if ( array_key_exists( 'status', $args ) ) {
			$execute_args['status'] = $args['status'];
		}

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

		return $result;
	}
}
