<?php

declare( strict_types=1 );

namespace Simplyin\Simplyin_W_Plugin\Tests\Unit;

use PHPUnit\Framework\TestCase;
use Simplyin\Simplyin_W_Plugin\Service\Order\Payment_Method_Label;

/**
 * Minimal WC_Order stub (base class stubbed in tests/bootstrap.php) exposing only what
 * Payment_Method_Label reads:
 * the gateway id (slug) and the human gateway title persisted at checkout.
 */
class Fake_Payment_Label_Order extends \WC_Order { // phpcs:ignore
	/** @var string */
	private $payment_method;
	/** @var string */
	private $payment_method_title;

	public function __construct( string $payment_method, string $payment_method_title ) {
		$this->payment_method       = $payment_method;
		$this->payment_method_title = $payment_method_title;
	}

	public function get_payment_method(): string {
		return $this->payment_method;
	}

	public function get_payment_method_title(): string {
		return $this->payment_method_title;
	}
}

/**
 * Contract for the payment-method labels in the SIN.CORE createOrder payload.
 *
 * Case A — order paid via the Simply.IN gateway: baseline `method` = "Simply.IN",
 * `title` = ''. Provider + instrument enrichment happens in SIN.CORE at payment
 * time, never in this payload (on the order-created hook the payment
 * has not run yet; in block checkout the instrument data does not exist server-side).
 *
 * Case B — native shop gateway: `method` = human gateway name (not the slug),
 * `title` = ''.
 */
final class Payment_Method_Label_Test extends TestCase {

	public function test_case_a_simplyin_order_returns_baseline_label(): void {
		// The stored WC title for the simplyin gateway is its checkout display name
		// ("Simple and Safe payments") — the payload must still say "Simply.IN".
		$order = new Fake_Payment_Label_Order( 'simplyin', 'Simple and Safe payments' );

		$this->assertSame(
			[
				'method' => 'Simply.IN',
				'title'  => '',
			],
			Payment_Method_Label::for_order( $order )
		);
	}

	public function test_case_b_native_gateway_uses_human_name_not_slug(): void {
		$order = new Fake_Payment_Label_Order( 'cod', 'Za pobraniem' );

		$this->assertSame(
			[
				'method' => 'Za pobraniem',
				'title'  => '',
			],
			Payment_Method_Label::for_order( $order )
		);
	}

	public function test_case_b_falls_back_to_slug_when_no_title_stored(): void {
		$order = new Fake_Payment_Label_Order( 'paypal', '' );

		$this->assertSame(
			[
				'method' => 'paypal',
				'title'  => '',
			],
			Payment_Method_Label::for_order( $order )
		);
	}
}
