<?php

declare(strict_types=1);

namespace WeeConnectPay\Api\Requests;

use WeeConnectPay\Dependencies\Psr\Http\Message\ResponseInterface;
use WeeConnectPay\Api\ApiClient;
use WeeConnectPay\Api\ApiEndpoints;

/**
 * Request class for updating payment method
 *
 * This class handles API requests to update saved payment method credentials
 * on the WeeConnectPay/Clover backend.
 *
 * @package WeeConnectPay
 * @subpackage WeeConnectPay/Api/Requests
 * @since 3.14.0
 */
class UpdatePaymentMethodRequest extends ApiClient {

	/**
	 * PUT request to update a payment method
	 *
	 * @since 3.14.0
	 * @param string $tokenizedCardUuid The UUID of the tokenized card to update
	 * @param string $tokenizedCard The tokenized card to update
	 * @return ResponseInterface
	 */
	public function PUT( ?string $tokenizedCardUuid, ?string $tokenizedCard ): ResponseInterface {
		return $this->client->put(
			ApiEndpoints::updatePaymentMethod( $tokenizedCardUuid ),
			self::setOptions( $tokenizedCard )
		);
	}

	/**
	 * Set request options for the payment method update
	 *
	 * @since 3.14.0
	 * @param string $tokenizedCard The tokenized card to update
	 * @return array The formatted options array
	 */
	private static function setOptions( ?string $tokenizedCard ): array {
		$options['json'] = self::setRequestBody( $tokenizedCard );
		return $options;
	}

	/**
	 * Set the request body for updating payment method
	 *
	 * @since 3.14.0
	 * @param string $tokenizedCard The tokenized card to update
	 * @return array The formatted request body
	 */
	private static function setRequestBody( ?string $tokenizedCard ): array {
		$params = array();

		$params['token_type']  = 'CARD_TOKEN';
		$params['value']       = $tokenizedCard;
		$params['is_multipay'] = true;

		return $params;
	}
} 