<?php

namespace Tests\Unit;

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

class ZimuPayServiceTest extends TestCase
{
    public function test_signature_uses_ascii_sorted_non_empty_fields(): void
    {
        $signature = ZimuPayService::signature([
            'appId' => 'APP123',
            'nonce' => 'abcdef',
            'mchOrderNo' => 'PO1',
            'amount' => '40.00',
            'member' => 'user1',
            'notifyUrl' => 'https://example.com/api/pay/harvest',
            'extParam' => '',
            'timestamp' => '1697253582897',
        ], 'secret');

        $this->assertSame('3C5D52F6411F9153ED34FEC1DAFA74C0', $signature);
    }

    public function test_channel_helpers_match_zimu_channels(): void
    {
        $this->assertTrue(ZimuPayService::isRechargeChannel(ZimuPayService::CHANNEL_RECHARGE));
        $this->assertTrue(ZimuPayService::isWithdrawChannel(ZimuPayService::CHANNEL_WITHDRAW));
        $this->assertTrue(ZimuPayService::isCashChannel(ZimuPayService::CHANNEL_CASH));
        $this->assertTrue(ZimuPayService::isPayoutChannel(ZimuPayService::CHANNEL_WITHDRAW));
        $this->assertTrue(ZimuPayService::isPayoutChannel(ZimuPayService::CHANNEL_CASH));
    }

    public function test_cash_pay_method_matches_bank_name(): void
    {
        $this->assertSame('1', ZimuPayService::cashPayMethod('中国建设银行'));
        $this->assertSame('2', ZimuPayService::cashPayMethod('微信'));
        $this->assertSame('3', ZimuPayService::cashPayMethod('支付宝'));
        $this->assertSame('4', ZimuPayService::cashPayMethod('数字人民币'));
    }
}
