<?php

declare( strict_types=1 );

namespace Simplyin\Simplyin_W_Plugin\Tests\Unit;

use PHPUnit\Framework\TestCase;
use Simplyin\Simplyin_W_Plugin\Lib\Remote\SimplyInApi\Model\PaymentsGetAvailablePaymentMethods200ResponseInner as AvailablePaymentMethod;

/**
 * The backend's payment method identifiers ("slug") aren't a fixed, closed set known at
 * client-generation time. This generated model must accept any slug string without
 * throwing, or the whole payment-method array fails to deserialize (ObjectSerializer
 * aborts the entire list on the first bad item) the moment an unrecognized one appears.
 */
final class Payments_Get_Available_Payment_Methods_Response_Inner_Slug_Test extends TestCase {

	private function make_valid_data( array $overrides = [] ): array {
		return array_merge(
			[
				'payment_method_id' => '5c3a757a-0f13-40fb-b2c2-d0ca6902df39',
				'type'               => 'card',
				'type_name'          => 'Pay by card',
				'name'               => 'Pay by card',
				'slug'               => 'card',
				'payment_provider'   => [ 'id' => 'p24', 'name' => 'Przelewy24' ],
			],
			$overrides
		);
	}

	public function test_accepts_a_slug_not_on_the_old_closed_list(): void {
		$method = new AvailablePaymentMethod( $this->make_valid_data( [ 'slug' => 'pay_by_link_p24_paywall' ] ) );

		$this->assertSame( 'pay_by_link_p24_paywall', $method->getSlug() );
		$this->assertSame( [], $method->listInvalidProperties() );
	}

	public function test_set_slug_accepts_any_non_null_string(): void {
		$method = new AvailablePaymentMethod( $this->make_valid_data() );

		$method->setSlug( 'some_brand_new_provider_paywall' );

		$this->assertSame( 'some_brand_new_provider_paywall', $method->getSlug() );
	}

	public function test_set_slug_still_rejects_null(): void {
		$method = new AvailablePaymentMethod( $this->make_valid_data() );

		$this->expectException( \InvalidArgumentException::class );

		$method->setSlug( null );
	}
}
