<?php

namespace Tests\Unit;

use App\Services\Payment\NoPayService;
use PHPUnit\Framework\TestCase;

class NoPayServiceTest extends TestCase
{
    public function test_signature_matches_document_example(): void
    {
        $signature = NoPayService::signature([
            'appId' => 'CZJS4BABJ1ZAPUN8',
            'amount' => '50',
            'merchantMemberNo' => 'shuri',
            'merchantOrderNo' => 'order_01',
            'notifyUrl' => 'www.http://weihao.com',
            'paymentMethod' => 12,
            'timestamp' => 1698043692,
            'version' => 'v1',
        ], 'CZKb4DB0WNHx5K3ajvcVCeH3ykBCuDIS');

        $this->assertSame(
            '2ce6c3b7637266b74432faa1dd6a50de9ad358570759b86d9555c8d1a8decd13',
            $signature
        );
    }

    public function test_payment_method_matches_recharge_channel(): void
    {
        $this->assertSame(12, NoPayService::paymentMethod(NoPayService::CHANNEL_SCAN));
        $this->assertSame(13, NoPayService::paymentMethod(NoPayService::CHANNEL_BALANCE));
    }

    public function test_empty_recharge_user_allowlist_allows_every_user(): void
    {
        config(['app.no_pay_recharge_user_ids' => '']);

        $this->assertTrue(NoPayService::canUserRecharge(123));
    }

    public function test_recharge_user_allowlist_only_allows_configured_users(): void
    {
        config(['app.no_pay_recharge_user_ids' => '12, 34']);

        $this->assertTrue(NoPayService::canUserRecharge(12));
        $this->assertFalse(NoPayService::canUserRecharge(56));
    }
}
